コード例 #1
0
ファイル: Index.cshtml.cs プロジェクト: marax27/Algenic
        public async System.Threading.Tasks.Task OnGetAsync()
        {
            var currentUserId = _userManager.GetUserId(User);
            var contestsData  = new List <(int, string)>();

            foreach (var contest in _dbContext.Contests)
            {
                var contestsUsersQuery = ContestsUsersQuery.Create(contest.Id);
                var contestsUsers      = await _contestsUsersQueryHandler.HandleAsync(contestsUsersQuery);

                if (contestsUsers.UserIds.Contains(currentUserId) && contest.Status == Contest.ContestState.Completed)
                {
                    contestsData.Add((contest.Id, contest.Name));
                }
            }

            StartingPageViewModel = MapToStartingPageViewModel(contestsData);
        }
コード例 #2
0
        public async Task <IActionResult> OnGetAsync(int id)
        {
            var defaultRedirections = new DefaultRedirections(this);

            if (!User.Identity.IsAuthenticated)
            {
                return(defaultRedirections.ToLoginPage(HttpContext.Request.Path));
            }

            ContestId = id;
            var contestsUsersQuery = ContestsUsersQuery.Create(id);
            var contestsUsers      = await _contestsUsersQueryHandler.HandleAsync(contestsUsersQuery);

            var contest = await _context.Contests.FindAsync(id);

            var contestOwnerId = contest.IdentityUser.Id;
            var currentUserId  = _userManager.GetUserId(User);

            if (!contestsUsers.UserIds.Append(contestOwnerId).Contains(currentUserId) || contest.Status != Contest.ContestState.Completed)
            {
                return(defaultRedirections.ToAccessDeniedPage(HttpContext.Request.Path));
            }

            UsersResults = new List <UserResultsViewModel>();

            IEnumerable <string> usersToIterateOver = contestOwnerId == currentUserId ?
                                                      contestsUsers.UserIds : new[] { currentUserId };

            var ranking = await ContestRanking(contestsUsers.UserIds);

            foreach (var userId in usersToIterateOver)
            {
                var userResults = await AggregateUserResults(userId, ranking);

                UsersResults.Add(userResults);
            }

            return(Page());
        }