コード例 #1
0
        public async Task <ActionResult> Index(int id, int page = 1)
        {
            Party party = _partyService.GetPartyWithOwnerByID(id);

            if (party == null)
            {
                return(new NotFoundResult());
            }

            var authorizationResult = await _authorizationService.AuthorizeAsync(User, party, "ReadPartyOver18");

            if (authorizationResult.Succeeded)
            {
                int pageSize = 3;

                IQueryable <Participant> source = _partyService.ListAttendent().Where(x => x.PartyId == id);
                var count = source.Count();
                var items = source.Skip((page - 1) * pageSize).Take(pageSize).ProjectTo <PartyParticipants>(_mapper.ConfigurationProvider).ToList();

                PageViewModel pageViewModel = new PageViewModel(count, page, pageSize);

                _httpContextAccessor.HttpContext.Session.AddParty(id);

                PartyParticipantsViewModel partyParticipantsViewModel = new PartyParticipantsViewModel();
                partyParticipantsViewModel.PartyID           = id;
                partyParticipantsViewModel.PartyTitle        = party.Title;
                partyParticipantsViewModel.PartyParticipants = items;
                partyParticipantsViewModel.PageViewModel     = pageViewModel;

                return(View(partyParticipantsViewModel));
            }
            else
            {
                return(new ForbidResult());
            }
        }