public static void LockPlayersAndStartStats(Games game, NPGGFFLDataContext context) { if (!game.IsStarted) { var startDtm = DateTime.Now; var seasonWeek = context.SeasonWeeks.Where(sw => sw.StartDtm <= game.GameDtm && sw.EndDtm >= game.GameDtm).First(); context.ExecuteCommand("update games set IsLocked = 1, IsStarted = 1 where SeasonWeekId = {0} and GameId = {1}", (new string[] { seasonWeek.SeasonWeekId.ToString(), game.GameId.ToString() })); context.ExecuteCommand("update OwnerTeams set IsLocked = 1 where islocked = 0 and seasonweekid = {0} and exists (select 1 from players p where p.playerid = playerid and exists (select 1 from games g where g.seasonweekid = {1} and g.GameId = {2} and (g.HomeTeamId = p.teamid or g.AwayTeamId = p.TeamId)))", (new string[] { seasonWeek.SeasonWeekId.ToString(), seasonWeek.SeasonWeekId.ToString(), game.GameId.ToString() })); context.ExecuteCommand("insert into playerstats (playerid, gameid) select p.playerid, g.gameid from players p, games g WHERE (g.hometeamid = p.teamid or g.awayteamid = p.teamid) and g.seasonweekid = {0} and g.GameId = {1} and not exists (select 1 from playerstats ps where ps.playerid = p.playerid and ps.gameid = g.gameid)", (new string[] { seasonWeek.SeasonWeekId.ToString(), game.GameId.ToString() })); Console.WriteLine("Lock Players & Start Stats took " + (DateTime.Now - startDtm).TotalSeconds); } }
public static void MarkPlayerStatsFinal(Games game, NPGGFFLDataContext context) { if (game.IsFinal == 1) { context.ExecuteCommand("update playerstats set isfinal = 1 where gameid = {0} and isfinal = 0", (new string[] { game.GameId.ToString() })); } }
public static PlayerStats InsertPlayerStatsByPlayerIdGameId(NPGGFFLDataContext context, int playerId, int gameId) { var playerStatsExist = context.PlayerStats.Where(ps => ps.PlayerId == playerId && ps.GameId == gameId).FirstOrDefault(); if (playerStatsExist == null) { context.ExecuteCommand("insert into playerstats (playerid, gameid) values ({0}, {1})", (new string[] { playerId.ToString(), gameId.ToString() })); return context.PlayerStats.Where(ps => ps.PlayerId == playerId && ps.GameId == gameId).FirstOrDefault(); } else { return playerStatsExist; } }