private static void SaveResult() { using (PlayersDBEntities db = new PlayersDBEntities()) { if (!IsExist()) { BattlePlayer player = new BattlePlayer() { Name = Form1.playerName, WinAmount = countWin, DefeatAmount = countDefeat, }; if (countDefeat == 0) { player.Rating = (double)countWin; } else { player.Rating = (double)(countWin / countDefeat); } db.BattlePlayer.Add(player); db.SaveChanges(); } } }
private void AddOrEditPlayer() { var query = Players.GetPlayers(PlayerName); if (query != null) { foreach (var q in query) { if (q.WinAmount == null) { continue; } var win = (int)q.WinAmount + _controller.CountWin; if (q.DefeatAmount == null) { continue; } var defeat = (int)q.DefeatAmount + _controller.CountDefeat; int rating; if (defeat == 0) { rating = win + RatingConst; } else { rating = (win / defeat) + RatingConst; } q.WinAmount = win; q.DefeatAmount = defeat; q.Rating = rating; } Players.Save(); } else { var player = new BattlePlayer { Name = PlayerName, WinAmount = _controller.CountWin, DefeatAmount = _controller.CountDefeat }; if (_controller.CountDefeat != 0) { player.Rating = _controller.CountWin / _controller.CountDefeat + RatingConst; } else { player.Rating = _controller.CountWin + RatingConst; } Players.Create(player); Players.Save(); } }