public string EloDifference(bool playerIsChallenger, Game game)
 {
     int pointSwing = (int)(playerIsChallenger ? game.pointSwing : -game.pointSwing);
     return  pointSwing > 0 ? string.Format("+{0}", pointSwing) : string.Format("{0}", pointSwing);
 }
 public GamesDeleteViewModel(Game game)
 {
     _game = game;
 }
 public ActionResult Create(GamesCreateViewModel gamevM)
 {
     try
     {
         if (String.IsNullOrEmpty(User.Identity.Name))
         {
             return RedirectToAction("Login", "Account");
         }
         Game game=new Game();
         game.Weight = 30;
         game.IsRankedGame = true;
         game.VerifiedById = 0;
         game.GamePlayedDate = DateTime.UtcNow;
         game.ChallengerSecondId = -1;
         game.DefenderSecondId = -1;
         game.GameTypeId = 1;
         var players=PlayerService.GetAllPlayersRestricted();
         Player defender = players.Where(a => a.LoginName == gamevM.OpponenUsername).FirstOrDefault();
         game.DefenderId = defender.PlayerId;
         game.DefenderEloRating = (int)defender.CurrentEloRating;
         Player challenger = players.Where(a => a.LoginName == User.Identity.Name).FirstOrDefault();
         game.ChallengerId = challenger.PlayerId;
         game.ChallengerEloRating = (int)challenger.CurrentEloRating;
         game.DefenderWon = !gamevM.YouWonFlag;
         double challengerEloChange=GetChallengerEloChange(game);
         game.pointSwing = challengerEloChange;
         GameService.CreateNewGame(game);
         challenger.CurrentEloRating += challengerEloChange;
         defender.CurrentEloRating -= challengerEloChange;
         PlayerService.UpdateExistingPlayer(challenger);
         PlayerService.UpdateExistingPlayer(defender);
         return RedirectToAction("Index");
     }
     catch
     {
         var players = PlayerService.GetAllPlayersRestricted();
         var usernames = new List<string>();
         foreach (Player player in players)
         {
             usernames.Add(player.LoginName);
         }
         var a = new GamesCreateViewModel();
         a.Usernames = usernames;
         return View(a);
     }
 }
 private double GetChallengerEloChange(Game game)
 {
     return EloCalculator.GetPlayerEloChange(game.ChallengerEloRating, game.DefenderEloRating, !game.DefenderWon, game.Weight);
 }
 /// <summary>
 /// Deletes an existing game
 /// </summary>
 public static void DeleteExistingGame(Game game)
 {
     IPingPongRepository<Game> _repo = new PingPongRepository<Game>();
     _repo.Delete(game.GameId);
 }
 /// <summary>
 /// Creates a new game
 /// </summary>
 public static void CreateNewGame(Game game)
 {
     IPingPongRepository<Game> _repo = new PingPongRepository<Game>();
     _repo.Create(game);
 }
 /// <summary>
 /// Updates an existing game
 /// </summary>
 public static void UpdateExistingGame(Game game)
 {
     IPingPongRepository<Game> _repo = new PingPongRepository<Game>();
     _repo.Update(game);
 }