Example #1
0
        public async Task <ActionResult <IEnumerable <Apartment> > > GetAllApartments(decimal fromPrice, decimal toPrice, string address, int numberOfRooms)
        {
            var paginationFilter = new PaginationFilter();
            var validFilter      = new PaginationFilter(paginationFilter.PageNumber, paginationFilter.PageSize);
            IEnumerable <Apartment> apartments;

            if (fromPrice == 0 && toPrice == 0 && address == null && numberOfRooms == 0)
            {
                apartments = await _apartmentService.GetAllApartments();
            }
            else
            {
                apartments = await _apartmentService.GetAllApartments(fromPrice, toPrice, address, numberOfRooms);
            }
            var route        = Request.Path.Value;
            var totalRecords = await _apartmentService.GetAllApartmentsCount();

            var apartmentResources = _mapper.Map <IEnumerable <Apartment>, IEnumerable <ApartmentResource> >(apartments);
            var pagedResponse      = PaginationHelper.CreatePagedResponse <IEnumerable <ApartmentResource> >(apartmentResources, validFilter, totalRecords, _uriService, route);

            return(Ok(pagedResponse));
        }