Exemplo n.º 1
0
        /// <inheritdoc/>
        public async Task <ListQueryResult <TReturn> > Handle(ListQuery <TReturn> request, CancellationToken cancellationToken)
        {
            try
            {
                request.ValidateModel();

                var entities = await repository.AnyAsync(
                    request.Skip,
                    request.Take,
                    request.SortOrder);

                var data = mapper.Map <IEnumerable <TReturn> >(entities)
                           ?? throw new InvalidOperationException($"Mapping {typeof(TEntity)} to {typeof(TReturn)}");

                var totalElements = await repository.CountAsync();

                return(new ListQueryResult <TReturn>(
                           data,
                           totalElements,
                           request.Skip,
                           request.Take,
                           request.SortOrder,
                           request.Draw));
            }
            catch (Exception ex)
            {
                Logger.Error(ex);
                throw;
            }
        }