Ejemplo n.º 1
0
        public async Task <SpecificationIndexViewModel> SearchSpecifications(SpecificationFilterViewModel filterViewModel)
        {
            var filter = _mapper.Map <SpecificationFilterViewModel, SpecificationFilter>(filterViewModel);

            var specifications = await _specificationService.SearchSpecificationsAsync(filter);

            var totalItems = await _specificationService.CountSpecificationsAsync(filter);

            var totalPages = int.Parse(Math.Ceiling(((decimal)totalItems / filter.pageSize)).ToString());

            return(new SpecificationIndexViewModel()
            {
                Items = _mapper.Map <IEnumerable <Specification>, List <SpecificationIndexItemViewModel> >(specifications),
                PaginationViewModel = new PaginationViewModel()
                {
                    TotalItems = totalItems,
                    PageSize = filter.pageSize,
                    PageIndex = filter.pageIndex,
                    TotalPages = totalPages,
                }
            });
        }