Пример #1
0
        public async Task <IActionResult> OnGetAddMemberAsync(int teamId, int userId, int applicationId)
        {
            if (EventRole == EventRole.play && !Event.IsTeamMembershipChangeActive)
            {
                return(NotFound("Team membership change is not currently active."));
            }

            TeamApplication application = await(from app in _context.TeamApplications
                                                where app.ID == applicationId
                                                select app).FirstOrDefaultAsync();

            if (application == null)
            {
                return(NotFound("Could not find application"));
            }

            if (application.Player.ID != userId)
            {
                return(NotFound("Mismatched player and application"));
            }
            Team team = await _context.Teams.FirstOrDefaultAsync(m => m.ID == teamId);

            if (application.Team != team)
            {
                return(Forbid());
            }

            Tuple <bool, string> result = TeamHelper.AddMemberAsync(_context, Event, EventRole, teamId, userId).Result;

            if (result.Item1)
            {
                return(RedirectToPage("./Details", new { teamId = teamId }));
            }
            return(NotFound(result.Item2));
        }
        public async Task <IActionResult> OnGetAddMemberAsync(int teamId, int userId, int applicationId)
        {
            Tuple <bool, string> result = TeamHelper.AddMemberAsync(_context, Event, EventRole, teamId, userId).Result;

            if (result.Item1)
            {
                return(RedirectToPage("./Details", new { teamId = teamId }));
            }
            return(NotFound(result.Item2));
        }
Пример #3
0
        public async Task <IActionResult> OnGet(int teamID, string password)
        {
            if (LoggedInUser == null)
            {
                return(Challenge());
            }

            if (EventRole != EventRole.play || IsNotAllowedInInternEvent())
            {
                return(Forbid());
            }

            if (!Event.IsTeamMembershipChangeActive)
            {
                return(NotFound("Team membership change is not currently allowed."));
            }

            TeamMembers playerTeam = await(from member in _context.TeamMembers
                                           where member.Member == LoggedInUser &&
                                           member.Team.Event == Event
                                           select member).FirstOrDefaultAsync();

            if (playerTeam != null)
            {
                return(RedirectToPage("./Details", new { teamId = playerTeam.Team.ID }));
            }

            Team = await(from t in _context.Teams
                         where t.ID == teamID && t.Event == Event
                         select t).FirstOrDefaultAsync();

            if (Team == null)
            {
                return(NotFound());
            }

            if (password != null && password == Team.Password)
            {
                Tuple <bool, string> result = await TeamHelper.AddMemberAsync(_context, Event, EventRole, teamID, LoggedInUser.ID);

                if (result.Item1)
                {
                    return(RedirectToPage("./Details", new { teamId = teamID }));
                }
                return(NotFound(result.Item2));
            }

            // Only handle one application at a time for a player to avoid spamming all teams
            IEnumerable <TeamApplication> oldApplications = from oldApplication in _context.TeamApplications
                                                            where oldApplication.Player == LoggedInUser && oldApplication.Team.Event == Event
                                                            select oldApplication;

            _context.TeamApplications.RemoveRange(oldApplications);

            TeamApplication application = new TeamApplication()
            {
                Team   = Team,
                Player = LoggedInUser
            };

            _context.TeamApplications.Add(application);

            await _context.SaveChangesAsync();

            MailHelper.Singleton.SendPlaintextOneAddress(Team.PrimaryContactEmail,
                                                         $"{Event.Name}: {LoggedInUser.Name} is applying to join {Team.Name}",
                                                         $"You can contact {LoggedInUser.Name} at {LoggedInUser.Email}. To accept or reject this request, visit your team page at http://puzzlehunt.azurewebsites.net/{Event.ID}/play/Teams/{Team.ID}/Details.");

            return(Page());
        }