// To protect from overposting attacks, enable the specific properties you want to bind to, for // more details, see https://aka.ms/RazorPagesCRUD. public async Task <IActionResult> OnPostAsync() { if (!ModelState.IsValid) { return(Page()); } _context.Attach(FootballGame).State = EntityState.Modified; try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!FootballGameExists(FootballGame.Id)) { return(NotFound()); } else { throw; } } return(RedirectToPage("./Index")); }
public async Task <IActionResult> OnPostAsync(int?id) { if (id == null) { return(NotFound()); } var UserAccount = await _context.UserAccounts .AsNoTracking() .FirstOrDefaultAsync(m => m.ID == id).ConfigureAwait(false); if (UserAccount == null) { return(NotFound()); } try { _context.UserAccounts.Remove(UserAccount); await _context.SaveChangesAsync().ConfigureAwait(false); return(Content(UserAccount.Name + " successfully deleted!")); } catch (DbUpdateException) { return(Content("Error")); } }
public async Task <IActionResult> OnPostAsync(Player Player, bool Football) { if (!ModelState.IsValid) { return(Content("Error - Model state is invalid.")); } if (Player != null) { Player NewPlayer = SportsFactory.CreatePlayer(Player); _context.Players.Add(NewPlayer); if (Football) { FootballPlayer NewFootballPlayer = SportsFactory.CreateFootballPlayer(NewPlayer); _context.FootballPlayers.Add(NewFootballPlayer); } await _context.SaveChangesAsync().ConfigureAwait(true); return(Content(NewPlayer.FirstName + " has been created!")); } return(Content("Error - Could not create Player.")); }
public async Task <IActionResult> OnPostAsync(FootballPlayer FootballPlayer) { FootballPlayer FootballPlayerToUpdate = await _context.FootballPlayers.FirstOrDefaultAsync(m => m.Id == FootballPlayer.Id).ConfigureAwait(false); if (null == FootballPlayerToUpdate) { return(Content("Error - Football player does not exist.")); } FootballPlayerToUpdate.CentreBack = FootballPlayer.CentreBack; FootballPlayerToUpdate.Sweeper = FootballPlayer.Sweeper; FootballPlayerToUpdate.FullBack = FootballPlayer.FullBack; FootballPlayerToUpdate.WingBack = FootballPlayer.WingBack; FootballPlayerToUpdate.CentreMidfield = FootballPlayer.CentreMidfield; FootballPlayerToUpdate.DefensiveMidfield = FootballPlayer.DefensiveMidfield; FootballPlayerToUpdate.AttackingMidfield = FootballPlayer.AttackingMidfield; FootballPlayerToUpdate.WideMidfield = FootballPlayer.WideMidfield; FootballPlayerToUpdate.Forward = FootballPlayer.Forward; FootballPlayerToUpdate.CentreForward = FootballPlayer.CentreForward; FootballPlayerToUpdate.Winger = FootballPlayer.Winger; FootballPlayerToUpdate.SetRating(); int result = await _context.SaveChangesAsync().ConfigureAwait(false); if (result == 1) { return(Content($"{FootballPlayerToUpdate.Player.FirstName} has been updated!")); } return(Content("Error - please contact your system administrator")); }
// To protect from overposting attacks, enable the specific properties you want to bind to, for // more details, see https://aka.ms/RazorPagesCRUD. public async Task <IActionResult> OnPostAsync() { if (!ModelState.IsValid) { return(Page()); } _context.FootballPlayers.Add(FootballPlayer); await _context.SaveChangesAsync(); return(RedirectToPage("./Index")); }
public async Task <IActionResult> OnPostAsync(int?id) { if (id == null) { return(NotFound()); } FootballPlayer = await _context.FootballPlayers.FindAsync(id); if (FootballPlayer != null) { _context.FootballPlayers.Remove(FootballPlayer); await _context.SaveChangesAsync(); } return(RedirectToPage("./Index")); }