Exemplo n.º 1
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.º 2
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,
            }));
        }