Exemplo 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,
            }));
        }
Exemplo 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,
            }));
        }
Exemplo n.º 3
0
        public async Task <IActionResult> OnPostAsync(string EventID, string TeamID, string ScoutedMatchID)
        {
            if (!ModelState.IsValid)
            {
                return(Page());
            }

            if (EventID == null || TeamID == null || ScoutedMatchID == null)
            {
                return(NotFound());
            }
            if (!AuthorizationCheck.ScoutedMatch(_context, ScoutedMatchID, User.Identity.Name))
            {
                return(Forbid());
            }

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

            eventID             = EventID;
            teamID              = TeamID;
            ScoutedMatch.TeamID = TeamID;
            ScoutedMatch.Score  = CalculateTeamMetrics.ComputeScoutedMatchScore(ScoutedMatch);

            Team ScoutedTeam = await _context.Team.FindAsync(TeamID);

            try
            {
                await _context.SaveChangesAsync();

                IList <int> Scores = await _context.ScoutedMatch.AsNoTracking().Where(s => s.TeamID == TeamID).Select(s => s.Score).ToListAsync();

                ScoutedTeam.AvgPTS = Math.Round(Scores.Average(), 1);
                _context.Team.Update(ScoutedTeam);
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!ScoutedMatchExists(ScoutedMatch.ID))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(RedirectToPage("./Index", new { EventID = eventID, TeamID = teamID, }));
        }
Exemplo n.º 4
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,
            }));
        }
Exemplo n.º 5
0
        public async Task <IActionResult> OnPostAsync(string EventID, string TeamID)
        {
            if (EventID == null || TeamID == null)
            {
                return(NotFound());
            }
            if (!AuthorizationCheck.Team(_context, TeamID, User.Identity.Name))
            {
                return(Forbid());
            }

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

            eventID             = EventID;
            teamID              = TeamID;
            ScoutedMatch.TeamID = TeamID;
            ScoutedMatch.Score  = CalculateTeamMetrics.ComputeScoutedMatchScore(ScoutedMatch);
            _context.ScoutedMatch.Add(ScoutedMatch);

            Team ScoutedTeam = await _context.Team.FindAsync(TeamID);

            IList <int> Scores = await _context.ScoutedMatch.AsNoTracking().Where(s => s.TeamID == TeamID).Select(s => s.Score).ToListAsync();

            Scores.Add(ScoutedMatch.Score);
            ScoutedTeam.AvgPTS = Math.Round(Scores.Average(), 1);

            _context.Team.Update(ScoutedTeam);
            await _context.SaveChangesAsync();

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