public void SaveGameResult(DrawingGameParams bgp) { using (var context = new GameModelContainer()) { var date = DateTime.Now; var game = context.Games.FirstOrDefault(b => b.Name == "DrawingGame"); if (game == null) return; var historyParams = new List<HistoryParam> { new HistoryParam { GameParam = game.GameParams.FirstOrDefault(param => param.Name == "Level"), Value = bgp.Level.ToString(CultureInfo.InvariantCulture) } }; var historyResults = new List<HistoryResult> { new HistoryResult { GameResult = game.GameResults.FirstOrDefault(result => result.Name == "Time"), Value = bgp.TimeOfGame }, new HistoryResult { GameResult = game.GameResults.FirstOrDefault(result => result.Name == "Time Out"), Value = bgp.TimeOutOfField } }; 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(); } }
public void SaveResults() { int level = 0; if (_mainWindow.Configuration.HandsState == 1 && _mainWindow.Configuration.Difficulty == 1) level = 1; if (_mainWindow.Configuration.HandsState == 2 && _mainWindow.Configuration.Difficulty == 1) level = 2; if (_mainWindow.Configuration.HandsState == 1 && _mainWindow.Configuration.Difficulty == 2) level = 3; if (_mainWindow.Configuration.HandsState == 2 && _mainWindow.Configuration.Difficulty == 2) level = 4; DrawingGameManager manager = new DrawingGameManager(_mainWindow.Configuration.Player); DrawingGameParams gameParams = new DrawingGameParams { TimeOfGame =(int)Math.Round((double) _mainWindow.StopwatchOfGame.ElapsedMilliseconds/1000), TimeOutOfField = (int)Math.Round((double) _mainWindow.StopwatchOfOutOfField.ElapsedMilliseconds / 1000), Level = level }; manager.SaveGameResult(gameParams); }