Ejemplo n.º 1
0
        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,
            }));
        }
Ejemplo n.º 2
0
        public async Task <IActionResult> OnPostAsync(string EventID)
        {
            if (EventID == null)
            {
                return(NotFound());
            }
            if (!AuthorizationCheck.Event(_context, EventID, User.Identity.Name))
            {
                return(Forbid());
            }

            if (!ModelState.IsValid)
            {
                return(Page());
            }
            OfficialMatch.EventID = EventID;
            _context.OfficialMatch.Add(OfficialMatch);

            IList <Models.OfficialMatch> AuthorizedOfficialMatches = await _context.OfficialMatch.Where(s => s.EventID == EventID).ToListAsync();

            AuthorizedOfficialMatches.Add(OfficialMatch);
            AuthorizedTeams = await _context.Team.AsNoTracking().Where(t => t.EventID == EventID).ToListAsync();

            IList <Team> TeamsWithScores = CalculateTeamMetrics.CalculateAllMetrics(AuthorizedTeams, AuthorizedOfficialMatches);

            _context.Team.UpdateRange(TeamsWithScores);
            await _context.SaveChangesAsync();

            var _EventID = EventID;

            return(RedirectToPage("./Index", new
            {
                EventID = _EventID,
            }));
        }
Ejemplo n.º 3
0
        public async Task <IActionResult> OnPostAsync(string EventID, string OfficialMatchID)
        {
            if (EventID == null || OfficialMatchID == null)
            {
                return(NotFound());
            }

            if (!ModelState.IsValid)
            {
                return(Page());
            }

            _context.Attach(OfficialMatch).State = EntityState.Modified;

            IList <Models.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);

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!OfficialMatchExists(OfficialMatch.ID))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            eventID = EventID;
            return(RedirectToPage("./Index", new
            {
                EventID = eventID,
            }));
        }