public ActionResult Submit(string returnUrl) { ViewBag.ReturnUrl = returnUrl; SubmitGameModel model = new SubmitGameModel(); model.SetWinningTeamDDL(Convert.ToInt32(Session["TeamID"])); model.SetWinningPlayersList(Convert.ToInt32(Session["TeamID"])); return View(model); }
public static void Submit(SubmitGameModel game) { // submitting a game to the db string sql = @"insert into Games (WinningTeamID, LosingTeamID, GameTypeID, WinningScore, LosingScore) values (@WinningTeamID, @LosingTeamID, @GameTypeID, @WinningScore, @LosingScore)"; using (SqlConnection conn = new SqlConnection(Main.GetDSN())) { SqlCommand command = new SqlCommand(sql, conn); command.Parameters.AddWithValue("@WinningTeamID", Convert.ToInt32(game.WinningTeamID)); command.Parameters.AddWithValue("@LosingTeamID", Convert.ToInt32(game.LosingTeamID)); command.Parameters.AddWithValue("@GameTypeID", Convert.ToInt32(game.GameTypeID)); command.Parameters.AddWithValue("@WinningScore", Convert.ToInt32(game.WinningScore)); command.Parameters.AddWithValue("@LosingScore", Convert.ToInt32(game.LosingScore)); conn.Open(); command.ExecuteNonQuery(); conn.Close(); } }
public ActionResult Submit(SubmitGameModel model, string returnUrl) { if (ModelState.IsValid) { // submit game .. then go to standings page ? GameLogic.Submit(model); TeamLogic.UpdateTeamSeasonStatRowsForGame(model); string winningPlayers = Request.Form["winningplayer"]; string losingPlayers = Request.Form["losingplayer"]; string[] winners = winningPlayers.Split(','); string[] losers = losingPlayers.Split(','); for (int i = 0; i < winners.Length; i++) { PlayerSeasonStat statRow = new PlayerSeasonStat(); statRow.UserID = Convert.ToInt32(winners[i]); statRow.Season = LeagueLogic.GetSeason(TeamLogic.GetLeagueID(Convert.ToInt32(model.WinningTeamID))); AccountLogic.UpdatePlayerSeasonStats(statRow, model); } for (int i = 0; i < losers.Length; i++) { PlayerSeasonStat statRow = new PlayerSeasonStat(); statRow.UserID = Convert.ToInt32(losers[i]); statRow.Season = LeagueLogic.GetSeason(TeamLogic.GetLeagueID(Convert.ToInt32(model.WinningTeamID))); AccountLogic.UpdatePlayerSeasonStats(statRow, model); } SubmitGameModel newModel = new SubmitGameModel(); newModel.SetWinningTeamDDL(Convert.ToInt32(Session["TeamID"])); newModel.SetWinningPlayersList(Convert.ToInt32(Session["TeamID"])); return View(newModel); } model.SetWinningTeamDDL(Convert.ToInt32(Session["TeamID"])); model.SetWinningPlayersList(Convert.ToInt32(Session["TeamID"])); return View(model); }
public static void UpdatePlayerSeasonStats(PlayerSeasonStat stats, SubmitGameModel game) { int teamID = GetTeamID(stats.UserID); int points = GameLogic.GetPointsForGameType(Convert.ToInt32(game.GameTypeID)); string sql = @"declare @Count int set @Count = (select count(pss.PlayerSeasonStatID) from PlayerSeasonStats pss where UserID = @UserID and Season = @Season) if @Count = 0 begin insert into PlayerSeasonStats (UserID, Wins, Losses, Season, Points) values (@UserID, case @Win when 1 then 1 else 0 end, case @Win when 1 then 0 else 1 end, @Season, @Points) end else if @Win = 1 begin update PlayerSeasonStats set Wins = Wins + 1, Points = Points + @Points where UserID = @UserID and Season = @Season end else update PlayerSeasonStats set Losses = Losses + 1 where UserID = @UserID and Season = @Season"; using (SqlConnection conn = new SqlConnection(Main.GetDSN())) { SqlCommand command = new SqlCommand(sql, conn); command.Parameters.AddWithValue("@UserID", stats.UserID); command.Parameters.AddWithValue("@Season", stats.Season); command.Parameters.AddWithValue("@Points", points); command.Parameters.AddWithValue("@Win", teamID == Convert.ToInt32(game.WinningTeamID)); conn.Open(); command.ExecuteNonQuery(); conn.Close(); } }
public static void UpdateTeamSeasonStatRowsForGame(SubmitGameModel game) { int season = LeagueLogic.GetSeason(GetLeagueID(Convert.ToInt32(game.WinningTeamID))); int points = GameLogic.GetPointsForGameType(Convert.ToInt32(game.GameTypeID)); string sql = @"update TeamSeasonStats set Wins = Wins + 1, Points = Points + @Points where TeamID = @WinningTeamID and Season = @Season update TeamSeasonStats set Losses = Losses + 1 where TeamID = @LosingTeamID and Season = @Season"; using (SqlConnection conn = new SqlConnection(Main.GetDSN())) { SqlCommand command = new SqlCommand(sql, conn); command.Parameters.AddWithValue("@WinningTeamID", game.WinningTeamID); command.Parameters.AddWithValue("@LosingTeamID", game.LosingTeamID); command.Parameters.AddWithValue("@Points", points); command.Parameters.AddWithValue("@Season", season); conn.Open(); command.ExecuteNonQuery(); conn.Close(); } }