Esempio n. 1
0
        public async Task <ActionResult> OnGetQuickAddTeam(string EventID, string TeamNumber, string TeamName, string OfficialMatchID)
        {
            if (EventID == null)
            {
                return(NotFound());
            }
            if (!AuthorizationCheck.Event(_context, EventID, User.Identity.Name))
            {
                return(Forbid());
            }

            Team Team = new Team
            {
                EventID    = EventID,
                TeamNumber = TeamNumber,
                TeamName   = TeamName
            };

            await _context.AddAsync(Team);

            await _context.SaveChangesAsync();

            var _EventID         = EventID;
            var _OfficialMatchID = OfficialMatchID;

            return(RedirectToPage("./Edit", new { EventID = _EventID, OfficialMatchID = _OfficialMatchID, }));
        }
Esempio n. 2
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, }));
        }
Esempio n. 3
0
        public async Task <ActionResult> OnGetDelete(string EventID, string TeamID)
        {
            if (EventID == null || TeamID == null)
            {
                return(NotFound());
            }
            if (!AuthorizationCheck.Team(_context, TeamID, User.Identity.Name))
            {
                return(Forbid());
            }

            IList <OfficialMatch> RemovedOfficialMatches = await _context.OfficialMatch.Where(o => o.Red1TeamID == TeamID || o.Red2TeamID == TeamID || o.Blue1TeamID == TeamID || o.Blue2TeamID == TeamID).ToListAsync();

            IList <ScoutedMatch> RemovedScoutedMatches = await _context.ScoutedMatch.Where(m => m.TeamID == TeamID).ToListAsync();

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

            if (Team != null)
            {
                _context.Team.Remove(Team);
                _context.RemoveRange(RemovedOfficialMatches);
                _context.RemoveRange(RemovedScoutedMatches);
                await _context.SaveChangesAsync();
            }

            var _EventID = EventID;

            return(RedirectToPage("./Index", new
            {
                EventID = _EventID,
            }));
        }
Esempio n. 4
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());
            }

            Team.EventID = EventID;
            Team.ExpPTS  = Services.CalculateTeamMetrics.ComputedTeamScore(Team);
            _context.Team.Add(Team);
            await _context.SaveChangesAsync();

            return(RedirectToPage("./Index", new
            {
                EventID = Team.EventID,
            }));
        }
Esempio n. 5
0
        public async Task <IActionResult> OnGetDelete(string EventID, string TeamID, string ScoutedMatchID)
        {
            if (EventID == null || TeamID == null || ScoutedMatchID == null)
            {
                return(NotFound());
            }
            if (!AuthorizationCheck.ScoutedMatch(_context, ScoutedMatchID, User.Identity.Name))
            {
                return(Forbid());
            }

            ScoutedMatch ScoutedMatch = await _context.ScoutedMatch.FindAsync(ScoutedMatchID);

            if (ScoutedMatch != null)
            {
                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.Remove(ScoutedMatch.Score);
                ScoutedTeam.AvgPTS = Math.Round(Scores.Average(), 1);
                _context.Team.Update(ScoutedTeam);
                _context.ScoutedMatch.Remove(ScoutedMatch);
                await _context.SaveChangesAsync();
            }

            var _EventID = EventID;
            var _TeamID  = TeamID;

            return(RedirectToPage("./Index", new
            {
                EventID = _EventID,
                TeamID = _TeamID,
            }));
        }
Esempio n. 6
0
        public async Task <ActionResult> OnGetDelete(string EventID)
        {
            if (EventID == null)
            {
                return(NotFound());
            }
            if (!AuthorizationCheck.Event(_context, EventID, User.Identity.Name))
            {
                return(Forbid());
            }

            Event Event = await _context.Event.FindAsync(EventID);

            if (Event != null)
            {
                List <Team> RemovedTeams = await _context.Team.Where(t => t.EventID == EventID).ToListAsync();

                List <OfficialMatch> RemovedOfficialMatches = await _context.OfficialMatch.Where(t => t.EventID == EventID).ToListAsync();

                _context.Team.RemoveRange(RemovedTeams);
                _context.OfficialMatch.RemoveRange(RemovedOfficialMatches);
                _context.Event.Remove(Event);
                await _context.SaveChangesAsync();
            }

            return(RedirectToPage("./Index"));
        }
Esempio n. 7
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,
            }));
        }
Esempio n. 8
0
        public async Task <IActionResult> OnPostAsync()
        {
            if (!ModelState.IsValid)
            {
                return(Page());
            }

            //Fixes for the allowed user tags so no one user can remove themselves from the event
            if (Event.AllowedUsers != String.Empty)
            {
                try
                {
                    if (!Event.AllowedUsers.Split(',').ToList().Contains(User.Identity.Name))
                    {
                        Event.AllowedUsers = User.Identity.Name + "," + Event.AllowedUsers;
                    }
                }
                catch
                {
                    if (Event.AllowedUsers != User.Identity.Name)
                    {
                        Event.AllowedUsers = User.Identity.Name + "," + Event.AllowedUsers;
                    }
                }
            }
            else
            {
                Event.AllowedUsers = User.Identity.Name;
            }

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

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

            return(RedirectToPage("./Index"));
        }
Esempio n. 9
0
        public async Task <IActionResult> OnPostAsync()
        {
            if (!ModelState.IsValid)
            {
                return(Page());
            }

            if (Event.AllowedUsers != String.Empty)
            {
                Event.AllowedUsers = User.Identity.Name + "," + Event.AllowedUsers;
            }
            else
            {
                Event.AllowedUsers = User.Identity.Name;
            }

            _context.Event.Add(Event);
            await _context.SaveChangesAsync();

            return(RedirectToPage("./Index"));
        }
Esempio n. 10
0
        public async Task <IActionResult> OnPostAsync(string EventID, string TeamID)
        {
            if (EventID == null || TeamID == null)
            {
                return(NotFound());
            }

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

            Team.ExpPTS = Services.CalculateTeamMetrics.ComputedTeamScore(Team);
            _context.Attach(Team).State = EntityState.Modified;

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

            var _EventID = EventID;
            var _TeamID  = TeamID;

            return(RedirectToPage("./Index", new
            {
                EventID = _EventID,
                TeamID = _TeamID,
            }));
        }
Esempio n. 11
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,
            }));
        }
Esempio n. 12
0
        public async Task <IActionResult> OnPostAsync()
        {
            if (!ModelState.IsValid)
            {
                return(Page());
            }

            Event       Event   = new Event();
            List <Team> Teams   = new List <Team>();
            var         request = new RestRequest();

            var eventClient = new RestClient("https://theorangealliance.org/api/event/" + TOAEventKey);

            eventClient.AddDefaultHeader("Content-Type", "application/json");
            eventClient.AddDefaultHeader("X-TOA-Key", "2c34a76a8b426e3f9bc7bb5d6b309196d3ef9a80978d8a1d3eef769280a7d491");
            eventClient.AddDefaultHeader("X-Application-Origin", "QR-FTCScoutingAppSkystone");
            var response = eventClient.Get(request);

            if (response.Content.Contains("\"_code\""))
            {
                return(RedirectToPage("/Error"));
            }

            TOAEvent TOAEvent = JsonConvert.DeserializeObject <TOAEvent>(response.Content.TrimStart('[').TrimEnd(']'));

            Event.Name         = TOAEvent.event_name;
            Event.AllowedUsers = User.Identity.Name + ',';
            Event.Address      = TOAEvent.venue;
            Event.StartDate    = DateTime.Parse(TOAEvent.start_date);
            Event.EndDate      = DateTime.Parse(TOAEvent.end_date);

            _context.Event.Add(Event);

            var teamsClient = new RestClient("https://theorangealliance.org/api/event/" + TOAEventKey + "/teams");

            teamsClient.AddDefaultHeader("Content-Type", "application/json");
            teamsClient.AddDefaultHeader("X-TOA-Key", "2c34a76a8b426e3f9bc7bb5d6b309196d3ef9a80978d8a1d3eef769280a7d491");
            teamsClient.AddDefaultHeader("X-Application-Origin", "QR-FTCScoutingAppSkystone");
            var teamsResponse = teamsClient.Get(request);

            List <TOATeamExtended> TOATeamsExtended = JsonConvert.DeserializeObject <List <TOATeamExtended> >(teamsResponse.Content);

            foreach (var TOATeamExtended in TOATeamsExtended)
            {
                Team Team = new Team();
                Team.EventID    = Event.ID;
                Team.TeamName   = TOATeamExtended.team.team_name_short;
                Team.TeamNumber = TOATeamExtended.team.team_number;
                if (TOATeamExtended.team.city != "")
                {
                    Team.TeamAddress += TOATeamExtended.team.city + ", ";
                }

                if (TOATeamExtended.team.state_prov != "")
                {
                    Team.TeamAddress += TOATeamExtended.team.state_prov + ", ";
                }

                if (TOATeamExtended.team.country != "")
                {
                    Team.TeamAddress += TOATeamExtended.team.country + ", ";
                }

                if (TOATeamExtended.team.zip_code != "")
                {
                    Team.TeamAddress += TOATeamExtended.team.zip_code + ", ";
                }

                Team.TeamAddress = Team.TeamAddress.TrimEnd(' ');
                Team.TeamAddress = Team.TeamAddress.TrimEnd(',');
                Teams.Add(Team);
            }

            _context.Team.AddRange(Teams);

            await _context.SaveChangesAsync();

            return(RedirectToPage("./Index"));
        }