Esempio n. 1
0
        /// <inheritdoc/>
        public Task <PagedIdNameViewModel> Handle(GetContinentsQuery request, CancellationToken cancellationToken)
        {
            var pageNumber = request.PageNumber;
            var pageSize   = request.PageSize;

            GuardAgainst.LessThanOrEqualToZero(pageNumber, nameof(pageNumber));
            GuardAgainst.LessThanOrEqualToZero(pageSize, nameof(pageSize));

            return(_repository.GetContinents(pageNumber, pageSize)
                   .ContinueWith(t =>
            {
                GuardAgainst.FaultedOrCancelled(t);
                var items = t.Result;

                // would prefer to go parallel but entityframework doesn't support parallel operations against
                // the same dbContext, at least EF6 doesn't
                var count = _repository.GetTotalCountOfContinents().ResultIfGreaterThanZero(cancellationToken);

                return new PagedIdNameViewModel
                {
                    Count = count,
                    PageNumber = pageNumber,
                    PageSize = pageSize,
                    Items = items.Select(tuple => new IdNameViewModel {
                        Id = tuple.Id, Name = tuple.Name
                    }).ToList()
                };
            }, cancellationToken));
        }