Example #1
0
        protected string GetOrderByClause(string orderByIn)
        {
            if (!string.IsNullOrWhiteSpace(orderByIn) && orderByIn.Split(new[] { '.' }).Length > 1)
            {
                return(orderByIn);
            }

            return(DataServiceHelper.BuildOrderByClause <T, TU>(orderByIn, GetDefaultSorting(), Mapper));
        }
Example #2
0
        protected async Task <DataContracts.V1.Common.PagedResult <TU> > GetDbItemsAsync(int?pageIndex,
                                                                                         int?pageSize, string orderBy, IQueryable <T> baseQuery = null)
        {
            var itemSet = baseQuery ?? Repository.Data.AsQueryable();

            if (!pageSize.HasValue || pageSize.Value <= 0)
            {
                pageSize = PageSize;
            }

            orderBy = GetOrderByClause(orderBy);
            var query = itemSet.OrderBy(orderBy).AsQueryable();

            if (pageIndex.HasValue && pageIndex.Value > 0)
            {
                query = query.Skip((pageIndex.Value - 1) * pageSize.Value).Take(pageSize.Value);
            }

            var list = await query.ToListAsync();

            return(DataServiceHelper.BuildPagedResult(Mapper.Map <List <TU> >(list), itemSet.Count(), pageSize.Value));
        }