public PagedItemDTO GetItems(PagedItemCriteriaDTO dto) { var c = dto; var predicateSpec = new FilterItemSpecyfication(c.Status, c.CategoryId, c.SubcategoryId); var orderSpec = new OrderItemSpecyfication(c.SortBy); var items = _unitOfWork.ItemRepo.Find(predicateSpec, orderSpec); var result = new PagedItemDTO(); result.TotalPages = (int)Math.Ceiling((decimal)items.Count() / c.PageSize); items = items.Skip((c.PageNumber - 1) * c.PageSize).Take(c.PageSize).ToList(); result.Items = _mapper.Map <List <Item>, List <SimpleItemDTO> >(items.ToList()); return(result); }
public IActionResult Index(PagedItemCriteriaViewModel criteria) { if (criteria.PageNumber == null) { criteria.PageNumber = 1; } ViewBag.CategoryId = criteria.CategoryId; ViewBag.SortBy = criteria.SortBy; ViewBag.PageNumber = criteria.PageNumber; ViewBag.SubcategoryId = criteria.SubcategoryId; PagedItemCriteriaDTO criteriaDTO = _mapper.Map <PagedItemCriteriaViewModel, PagedItemCriteriaDTO> (criteria); criteriaDTO.PageSize = pageSize; criteriaDTO.Status = Status.InAuction; var dto = _service.GetItems(criteriaDTO); var model = _mapper.Map <PagedItemDTO, PagedItemViewModel> (dto); return(View(model)); }