public ActionResult Join(int id = 0) { using (var galleristContext = new GalleristComponentsDbContext()) { using (var identityContext = new ApplicationDbContext()) { var gameResponse = GameManager.GetGame(id, galleristContext); if (gameResponse.Success) { gameResponse.Game.Players.Add(new Player { UserId = identityContext.Users.First(m => m.UserName == User.Identity.Name).Id, UserName = User.Identity.Name }); PushHelper singleton = PushHelper.GetPushEngine(); singleton.RefreshGameList(gameResponse.Game.Players.Where(m => m.UserName != User.Identity.Name).Select(p => p.UserName).ToList()); ViewBag.userName = User.Identity.Name; galleristContext.SaveChanges(); return(Redirect("/Game/List")); } else { ViewBag.Message = gameResponse.Message; ViewBag.Title = gameResponse.Title; return(View("GameError")); } } } }
public ActionResult Leave(int id = 0) { using (var galleristContext = new GalleristComponentsDbContext()) { var gameResponse = GameManager.GetGame(id, galleristContext); var game = gameResponse.Game; if (game.IsStarted) { ViewBag.Message = "Cannot leave in progress game"; ViewBag.Title = "Error"; return(View("GameError")); } var playerLeaving = game.Players.First(m => m.UserName == User.Identity.Name); galleristContext.Players.Remove(playerLeaving); galleristContext.SaveChanges(); PushHelper singleton = PushHelper.GetPushEngine(); singleton.RefreshGameList(game.Players.Select(p => p.UserName).ToList()); return(Redirect("~/Game/List/")); } }