public void SaveGameResult(LettersGameParams lgp)
        {
            using (var context = new GameModelContainer())
            {
                var game = context.Games.FirstOrDefault(b => b.Name == "LettersGame");

                if (game == null)
                    return;

                var date = DateTime.Now;
                var historyParams = new List<HistoryParam>
                {
                    new HistoryParam
                    {
                        GameParam = game.GameParams.FirstOrDefault(param => param.Name == "Level"),
                        Value = lgp.Level.ToString(CultureInfo.InvariantCulture)
                    }
                };
                
                var historyResults = new List<HistoryResult>
                {
                    new HistoryResult
                    {
                        GameResult = game.GameResults.FirstOrDefault(param => param.Name == "Correct Trials"),
                        Value = lgp.CorrectTrials
                    },
                    new HistoryResult
                    {
                        GameResult = game.GameResults.FirstOrDefault(param => param.Name == "Failures"),
                        Value = lgp.Failures
                    },
                    new HistoryResult
                    {
                        GameResult = game.GameResults.FirstOrDefault(param => param.Name == "Time"),
                        Value = lgp.Time
                    }
                };

                var history = new History
                {
                    Game = game,
                    Date = date,
                    HistoryParams = historyParams,
                    HistoryResults = historyResults
                };
                var player = context.Players.FirstOrDefault(player1 => player1.Id == _player.Id);
                if (player != null) 
                    player.Histories.Add(history);
                context.SaveChanges();
            }
        }
Esempio n. 2
0
 private void SaveToDatabase()
 {
     var manager = new LettersGameManager(_config.Player);
     var gameParams = new LettersGameParams
     {
         Level = _config.CurrentLevel,
         LettersCount = _config.LettersCount,
         CorrectTrials = CorrectTrials,
         Failures = Fails,
         Time = (int)Time.TotalMilliseconds
     };
     manager.SaveGameResult(gameParams);
 }