コード例 #1
0
        public virtual PaginationSet <TEntity> GetPart(PaginationSetRequest request,
                                                       Expression <Func <TEntity, bool> > predicate)
        {
            request.Validate();

            var query = predicate != null?Where(predicate) : GetAllDbEntities();

            //todo: It is not sorted by int:ID, need to fix
            query = query.OrderBy(request.OrderBy, request.Descending);

            var offset = (request.PageIndex - 1) * request.PageSize;
            var batch  = query.GetBatch(offset, request.PageSize);

            if (batch.Status != BatchStatus.Full)
            {
                return(PaginationSet <TEntity> .Empty);
            }

            return(new PaginationSet <TEntity>
            {
                Page = request.PageIndex,
                TotalCount = batch.TotalRecordCount,
                TotalPages = (int)Math.Ceiling((decimal)batch.TotalRecordCount / request.PageSize),
                Items = batch.Items
            });
        }
コード例 #2
0
        public virtual IHttpActionResult Get([FromUri] PaginationSetRequest paginationSetRequest)
        {
            if (paginationSetRequest == null)
            {
                return(BadRequest());
            }
            var domainModel = ApiService.GetPart(paginationSetRequest);

            if (domainModel == PaginationSet <TDomain> .Empty)
            {
                return(NotFound());
            }
            var viewModel = Mapper.Map <PaginationSet <TVm> >(domainModel);

            return(Json(viewModel, new JsonSerializerSettings {
                ContractResolver = new CamelCasePropertyNamesContractResolver()
            }));
        }
コード例 #3
0
        public IHttpActionResult Get([FromUri] int ownerId, [FromUri] PaginationSetRequest petsRequest)
        {
            if (petsRequest == null)
            {
                return(BadRequest());
            }
            var domainModel = ApiService.GetPart(petsRequest, p => p.OwnerId == ownerId);

            if (domainModel == PaginationSet <Pet> .Empty)
            {
                return(NotFound());
            }
            var viewModel = Mapper.Map <PaginationSet <PetViewModel> >(domainModel);

            return(Json(viewModel, new JsonSerializerSettings {
                ContractResolver = new CamelCasePropertyNamesContractResolver()
            }));
        }
コード例 #4
0
 public virtual PaginationSet <TEntity> GetPart(PaginationSetRequest request)
 {
     return(GetPart(request, null));
 }