/** Save the bowl picks */ public void saveBowlPicks(Integer userId, List<BowlPickBo> bowlPicks) { UserManager userMgr = new UserManager(); User user = userMgr.getUserById(userId); Transaction saveTransaction = session.beginTransaction(); for (BowlPickBo bowlPickBo : bowlPicks) { BowlMatchup matchup = getMatchupById(bowlPickBo.getBowlMatchupId()); if (matchup.getLockFlag() == true) { continue; } BowlPick pick = null; if (bowlPickBo.getBowlPickId() != null) { pick = getBowlPickById(bowlPickBo.getBowlPickId()); } else { pick = new BowlPick(); } pick.setBowlMatchup(getMatchupById(bowlPickBo.getBowlMatchupId())); pick.setSelectedTeam(getCfbTeamById(bowlPickBo.getSelectedTeamId())); pick.setUser(user); pick.setLastEditTimestamp(new Date()); pick.setCreateTimestamp(new Date()); user.getBowlPicks().add(pick); if (pick.getBowlMatchup().getLockFlag() == true) { continue; } session.saveOrUpdate(pick); } saveTransaction.commit(); session.flush(); }
public String getUserBowlPickTotalScore(User user) { Integer pointsPossible = 0; for (BowlMatchup matchup : this.getAllBowlMatchups()) { if (matchup.getWinningTeam() != null) { pointsPossible++; } } Integer points = 0; for (BowlPick pick : user.getBowlPicks()) { CfbTeam pickedTeam = pick.getSelectedTeam(); CfbTeam winningTeam = pick.getBowlMatchup().getWinningTeam(); if (pickedTeam != null && winningTeam != null) { if (pickedTeam.getCfbTeamId() == winningTeam.getCfbTeamId()) { points++; } } } return points + " / " + pointsPossible; }
/** * @param bowlPick * @return Scored pick status */ public BowlPickStatus scoreBowlPick(BowlPick bowlPick) { BowlMatchup matchup = bowlPick.getBowlMatchup(); if (matchup.getWinningTeam() == null && matchup.getLockFlag() == false) { return BowlPickStatus.OPEN; } if (matchup.getWinningTeam() == null && matchup.getLockFlag() == true) { return BowlPickStatus.LOCKED; } if (matchup.getWinningTeam().getCfbTeamId() == bowlPick.getSelectedTeam().getCfbTeamId()) { return BowlPickStatus.RIGHT; } return BowlPickStatus.WRONG; }
/** * Save the bowl matchups. * * @param matchupBizObjs * @param deletedIds */ public void saveAllBowlMatchups(List<BowlMatchupBo> matchupBizObjs, List<Integer> deletedIds) { Transaction clearPicksTx = session.beginTransaction(); for (Integer matchupIdToDelete : deletedIds) { BowlMatchup matchup = getMatchupById(matchupIdToDelete); matchup.getBowlPicks().clear(); session.save(matchup); } clearPicksTx.commit(); session.flush(); Transaction deleteMatchupTx = session.beginTransaction(); for (Integer matchupIdToDelete : deletedIds) { BowlMatchup matchup = getMatchupById(matchupIdToDelete); session.delete(matchup); } deleteMatchupTx.commit(); session.flush(); Transaction saveTransaction = session.beginTransaction(); for (BowlMatchupBo matchupBo : matchupBizObjs) { BowlMatchup matchup = null; if (matchupBo.getMatchupId() != null) { matchup = this.getMatchupById(matchupBo.getMatchupId()); } else { matchup = new BowlMatchup(); } matchup.setDate(matchupBo.getDate()); matchup.setTitle(matchupBo.getTitle()); matchup.setTeamA(getCfbTeamById(matchupBo.getTeamA().getCfbTeamId())); matchup.setTeamB(getCfbTeamById(matchupBo.getTeamB().getCfbTeamId())); matchup.setTeamASpread(matchupBo.getTeamASpread()); matchup.setTeamBSpread(matchupBo.getTeamBSpread()); matchup.setTeamAScore(matchupBo.getTeamAScore()); matchup.setTeamBScore(matchupBo.getTeamBScore()); if (matchupBo.getWinningTeam() != null) { matchup.setWinningTeam(getCfbTeamById(matchupBo.getWinningTeam().getCfbTeamId())); } matchup.setLockFlag(matchupBo.getLockFlag()); matchup.setLastEditTimestamp(new Date()); matchup.setCreateTimestamp(new Date()); session.saveOrUpdate(matchup); } saveTransaction.commit(); session.flush(); }