Esempio n. 1
0
        public async Task <IActionResult> OnPostAsync()
        {
            if (Event != null)
            {
                using (var transaction = _context.Database.BeginTransaction())
                {
                    var eventTeams = from team in _context.Teams
                                     where team.Event == Event
                                     select team;

                    foreach (Team team in eventTeams)
                    {
                        await TeamHelper.DeleteTeamAsync(_context, team);
                    }

                    var eventPuzzles = from puzzle in _context.Puzzles
                                       where puzzle.Event == Event
                                       select puzzle;
                    foreach (Puzzle puzzle in eventPuzzles)
                    {
                        await PuzzleHelper.DeletePuzzleAsync(_context, puzzle);
                    }

                    _context.Events.Remove(Event);

                    await _context.SaveChangesAsync();

                    transaction.Commit();
                }
            }

            return(RedirectToPage("./Index"));
        }
Esempio n. 2
0
        public async Task <IActionResult> OnPostAsync(int teamId)
        {
            Team = await _context.Teams.FindAsync(teamId);

            var mergeIntoTeam = await _context.Teams.FindAsync(MergeIntoID);

            if (Team == null || mergeIntoTeam == null || Team.Event != Event || mergeIntoTeam.Event != Event)
            {
                return(NotFound());
            }

            List <string> memberEmails          = null;
            List <string> mergeIntoMemberEmails = null;

            using (var transaction = await _context.Database.BeginTransactionAsync(IsolationLevel.Serializable))
            {
                var members = await _context.TeamMembers.Where(tm => tm.Team.ID == teamId).ToListAsync();

                memberEmails = await _context.TeamMembers.Where(tm => tm.Team.ID == teamId).Select(tm => tm.Member.Email).ToListAsync();

                mergeIntoMemberEmails = await _context.TeamMembers.Where(tm => tm.Team.ID == MergeIntoID).Select(m => m.Member.Email).ToListAsync();

                var states = await PuzzleStateHelper.GetSparseQuery(_context, Team.Event, null, Team).ToListAsync();

                var mergeIntoStates = await PuzzleStateHelper.GetSparseQuery(_context, Team.Event, null, mergeIntoTeam).ToDictionaryAsync(s => s.PuzzleID);

                // copy all the team members over
                foreach (var member in members)
                {
                    member.Team = mergeIntoTeam;
                }

                // also copy puzzle solves over
                foreach (var state in states)
                {
                    if (state.SolvedTime != null && mergeIntoStates.TryGetValue(state.PuzzleID, out var mergeIntoState) && mergeIntoState.SolvedTime == null)
                    {
                        await PuzzleStateHelper.SetSolveStateAsync(_context, Team.Event, mergeIntoState.Puzzle, mergeIntoTeam, state.UnlockedTime);
                    }
                }

                await TeamHelper.DeleteTeamAsync(_context, Team, sendEmail : false);

                await _context.SaveChangesAsync();

                transaction.Commit();
            }

            MailHelper.Singleton.SendPlaintextWithoutBcc(memberEmails.Union(mergeIntoMemberEmails),
                                                         $"{Event.Name}: Team '{Team.Name}' has been merged into '{mergeIntoTeam.Name}'",
                                                         $"These two teams have been merged into one superteam. Please welcome your new teammates!");

            return(RedirectToPage("./Index"));
        }
Esempio n. 3
0
        public async Task <IActionResult> OnPostAsync(int teamId)
        {
            Team = await _context.Teams.FindAsync(teamId);

            if (Team != null)
            {
                await TeamHelper.DeleteTeamAsync(_context, Team);
            }

            if (EventRole == EventRole.admin)
            {
                return(RedirectToPage("./Index"));
            }
            else
            {
                return(RedirectToPage("./List"));
            }
        }