public async Task <IActionResult> OnGetAsync(string EventID, string OfficialMatchID) { if (EventID == null || OfficialMatchID == null) { return(NotFound()); } if (!AuthorizationCheck.OfficialMatch(_context, OfficialMatchID, User.Identity.Name)) { return(Forbid()); } if (await _context.Team.AsNoTracking().Where(t => t.EventID == EventID).CountAsync() < 4) { return(Forbid()); } eventID = EventID; OfficialMatch = await _context.OfficialMatch.FirstOrDefaultAsync(m => m.ID == OfficialMatchID); AuthorizedTeams = await _context.Team.AsNoTracking().Where(t => t.EventID == EventID).OrderBy(t => t.TeamNumber.PadLeft(5)).ToListAsync(); if (OfficialMatch == null) { return(NotFound()); } return(Page()); }
public async Task <ActionResult> OnGetDelete(string EventID, string OfficialMatchID) { if (EventID == null || OfficialMatchID == null) { return(NotFound()); } if (!AuthorizationCheck.OfficialMatch(_context, OfficialMatchID, User.Identity.Name)) { return(Forbid()); } OfficialMatch OfficialMatch = await _context.OfficialMatch.FindAsync(OfficialMatchID); IList <OfficialMatch> AuthorizedOfficialMatches = await _context.OfficialMatch.Where(s => s.EventID == EventID).ToListAsync(); AuthorizedTeams = await _context.Team.AsNoTracking().Where(t => t.EventID == EventID).ToListAsync(); IList <Team> TeamsWithScores = CalculateTeamMetrics.CalculateAllMetrics(AuthorizedTeams, AuthorizedOfficialMatches); _context.Team.UpdateRange(TeamsWithScores); if (OfficialMatch != null) { _context.OfficialMatch.Remove(OfficialMatch); await _context.SaveChangesAsync(); } var _EventID = EventID; return(RedirectToPage("./Index", new { EventID = _EventID, })); }