public static TeamGameplayModel Create(GameplayModel gameplay, UCTeam team) { var model = new TeamGameplayModel(gameplay, team); model.Initialize(); return(model); }
public static GameplayModel Create(int gameId, BBScoreboardEntities db = null) { var item = new GameplayModel(db == null ? new BBScoreboardEntities() : db, gameId); item.Initialize(); return(item); }
public TeamGameplayModel(GameplayModel gameplay, UCTeam team) { Gameplay = gameplay; TeamId = team.Id; }
public static int UpdateGame(int gameId, int quarter, bool updateScores, UCGameTeamStat ts0, UCGameTeamStat ts1, bool updateTime, DateTime timeLeft, DateTime timerLastModified, GameplayModel gp = null) { var gameplay = gp ?? GameplayModel.Create(gameId); var game = gameplay.Game; var now = DateTime.UtcNow; bool hasGameUpdates = false; if (updateScores) { for (int i = 0; i < 2; i++) { var t = i == 0 ? ts0 : ts1; var ts = gameplay.TeamModels[i].Stat; ts.Q1 = t.Q1; ts.Q2 = t.Q2; ts.Q3 = t.Q3; ts.Q4 = t.Q4; ts.LastUpdate = DateTime.UtcNow; } } if (updateTime) { game.TimeLeft = timeLeft; //GameHelper.ComputeTimeRemaining(game); game.TimeLastModified = timerLastModified; hasGameUpdates = true; } if (game.CurrentQuarter != quarter) { // Create player stats stats game.CurrentQuarter = quarter; var q = quarter > 4 ? 4 : quarter; for (int i = 0; i < 2; i++) { var teamModel = gameplay.TeamModels[i]; var stats = teamModel.QuarterPlayerStats; var players = teamModel.Players; foreach (var player in players) { var stat = stats.SingleOrDefault(item => item.PlayerId == player.Id); if (stat == null) { stat = new UCGamePlayerStat(); stat.PlayerId = player.Id; stat.TeamId = player.TeamId; stat.GameId = gameplay.GameId; stat.Quarter = q; gameplay.Db.UCGamePlayerStats.Add(stat); } } } hasGameUpdates = true; } if (hasGameUpdates) { game.LastUpdate = now; } if (hasGameUpdates || updateScores) { game.LastActivityDate = now; gameplay.Db.SaveChanges(); } return(0); }