Exemple #1
0
 public PagedListModel<OfferViewModel> Get(PagedListRequestModel requestModel)
 {
     return GetOffers(requestModel, x => x.Status == OfferStatus.Offered);
 }
Exemple #2
0
 public PagedListModel<OfferViewModel> GetCompleted(PagedListRequestModel requestModel)
 {
     return GetOffers(requestModel, x => x.Status == OfferStatus.Won || x.Status == OfferStatus.Lost);
 }
Exemple #3
0
        private PagedListModel<OfferViewModel> GetOffers(PagedListRequestModel requestModel, Expression<Func<Offer, bool>> filterExpression)
        {
            requestModel = requestModel ?? new PagedListRequestModel
            {
                PageSize = 20
            };
            var itemsToSkip = (requestModel.Page - 1) * requestModel.PageSize;

            var itemsQuery = Session.QueryOver<Offer>()
                .Where(filterExpression);
            if (!string.IsNullOrEmpty(requestModel.Filter))
                itemsQuery.Where(x => x.Title.IsInsensitiveLike(requestModel.Filter, MatchMode.Anywhere));
            if (!string.IsNullOrEmpty(requestModel.Sort))
                itemsQuery.UnderlyingCriteria.AddOrder(new Order(requestModel.Sort, requestModel.OrderAscending));
            itemsQuery
                .Skip(itemsToSkip)
                .Take(requestModel.PageSize);

            var items = itemsQuery.Future();
            var totalItems = itemsQuery.ToRowCountQuery().FutureValue<int>();

            return new PagedListModel<OfferViewModel>
            {
                Page = requestModel.Page,
                PageSize = requestModel.PageSize,
                TotalItems = totalItems.Value,
                TotalPages = (int)Math.Ceiling(totalItems.Value / (double)requestModel.PageSize),
                Items = Mapper.Map<IEnumerable<OfferViewModel>>(items)
            };
        }