예제 #1
0
        public static async Task <Response> GetResponseAsync <T>(this Request request, CollectionBase <T> service, IMapper mapper)
            where T : class
        {
            var response = new Response()
            {
                Draw = request.Draw
            };
            var filter     = request.GetQueryExpression <T>();
            var order      = request.GetOrderExpression <T>();
            var pagination = mapper.Map <Pagination>(request);
            var items      = await service.GetListAsync(filter, order, pagination);

            var total = await service.CountAsync();

            response.Filtered = filter.Statements.SelectMany(a => a).Any() ? items.Count : (int)total;
            response.Total    = (int)total;
            response.Data     = items;

            return(response);
        }