public async Task <IActionResult> OnPostAsync(int?id) { if (id == null) { return(NotFound()); } Match = await _context.Match .Include(m => m.Game) .Include(m => m.PlayerMatches) .ThenInclude(m => m.Player) .FirstAsync(m => m.MatchId == id); if (Match != null) { Match.Game.Matches.Remove(Match); _context.Game.Update(Match.Game); foreach (PlayerMatch p in Match.PlayerMatches) { p.Player.PlayerMatches.Remove(p); _context.Player.Update(p.Player); } Match.PlayerMatches.Clear(); _context.Match.Remove(Match); await _context.SaveChangesAsync(); } return(RedirectToPage("./Index")); }
public async Task <IActionResult> OnPostAsync() { if (!ModelState.IsValid) { return(Page()); } _context.Attach(Game).State = EntityState.Modified; try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!GameExists(Game.GameId)) { return(NotFound()); } else { throw; } } return(RedirectToPage("./Index")); }
public async Task <IActionResult> OnPostAsync(int?id) { if (id == null) { return(NotFound()); } Player = await _context.Player.FindAsync(id); if (Player != null) { _context.Player.Remove(Player); await _context.SaveChangesAsync(); } return(RedirectToPage("./Index")); }
public async Task <IActionResult> OnPostAsync() { if (!ModelState.IsValid) { return(Page()); } Game.ApplicationUser = await _userManager.GetUserAsync(User); if (Game.ApplicationUser == null) { throw new ApplicationException("Cannot create a game with a user."); } Game.ProgrammingLanguage = _context.ProgrammingLanguage.Where(l => l.ProgrammingLanguageId == SelectedLanguage).FirstOrDefault(); _context.Game.Add(Game); await _context.SaveChangesAsync(); return(RedirectToPage("./Index")); }
public async Task <IActionResult> OnPostAsync() { if (!ModelState.IsValid) { return(Page()); } if (SelectedPlayers.Count == 0) { throw new ApplicationException("Cannot create a match without any players."); } Match.Game = _context.Game.Where(g => g.GameId == SelectedGame).FirstOrDefault(); Match.PlayerMatches = new List <PlayerMatch>(); foreach (int id in SelectedPlayers) { Player player = _context.Player.Where(p => p.PlayerId == id).FirstOrDefault(); PlayerMatch playerMatch = new PlayerMatch() { Player = player, Match = Match }; Match.PlayerMatches.Add(playerMatch); // player.PlayerMatches.Add(playerMatch); // Match.PlayerMatches.Add(playerMatch); } _context.Match.Add(Match); await _context.SaveChangesAsync(); return(RedirectToPage("./Index")); }