Exemple #1
0
        public async Task <GetPagedPetition> GetPaged(GetPagedPetitionRequest request, CancellationToken cancellationToken)
        {
            if (!await _identityService.CurrentUserAdmin(cancellationToken))
            {
                throw new NoRightsException("Доступ к жалобам имеет только администратор.");
            }

            var total = await _petitionRepository.Count(cancellationToken);

            var result = _mapper.Map <GetPagedPetition>(request);

            if (total == 0)
            {
                return(result);
            }

            var petitions = await _petitionRepository.FindWhere(x => !x.Reviewed, cancellationToken);

            result.Items = _mapper.Map <GetPagedPetitionItem[]>(petitions.Skip(request.Offset).Take(request.Limit));
            result.Total = total;

            return(result);
        }