public static void CheckGameStatus(string twitchGameName, Channel channel) { var game = GameInstanceMethods.GetGameByTwitchName(twitchGameName); game = game == null ? GameInstanceMethods.CreateNewGame(twitchGameName) : game; bool gameIsCurrent = GameInstanceMethods.CheckIfGameIsCurrent(game, channel); if (gameIsCurrent) { var gameInstance = GameInstanceMethods.GetGameInstance(channel.ChannelId, twitchGameName); if (gameInstance.TimeSpanAdded == null) { TimeSpan spanBetweenFromAndNow = gameInstance.PlayedFrom - DateTime.Now; gameInstance.TotalTimePlayed = spanBetweenFromAndNow; gameInstance.TimeSpanAdded = DateTime.Now; } else { TimeSpan spanSinceLastCheck = gameInstance.TimeSpanAdded - DateTime.Now; gameInstance.TotalTimePlayed += spanSinceLastCheck; } StatisticService.CheckStatisticsForGame(channel.Statistic, game); GameInstanceMethods.SaveInstance(gameInstance); } else { var gameInstance = new GameInstance(game) { TotalViewersCount = 0, ChannelId = channel.ChannelId }; GameInstanceMethods.AddGameInstance(gameInstance); channel.DailyActivities .FirstOrDefault(d => d.ActivityDate == DateTime.Now) .GameInstances.Add(gameInstance); } }
public static void SaveInstance(GameInstance gameInstance) { var moonDb = new MoonAidAzureContext(); moonDb.Entry(gameInstance).State = EntityState.Modified; }
public static void AddGameInstance(GameInstance gameinstance) { var moonDb = new MoonAidAzureContext(); moonDb.GameInstances.Add(gameinstance); }