Esempio n. 1
0
        public async Task <IActionResult> FilterHouses(HouseFilterViewModel filterModel, string houseValue)
        {
            IEnumerable <House> filteredHouses;

            if (!string.IsNullOrEmpty(houseValue))
            {
                filteredHouses = await _houseService.GetFilteredHouses(houseValue, houseValue);

                return(View("HousesSection", new HousesSectionViewModel()
                {
                    Houses = _mapper.Map <IEnumerable <SectionHouseViewModel> >(filteredHouses),
                    HousesMaxPrice = await _houseService.GetMaxHousePrice(),
                    HousesMinPrice = await _houseService.GetMinHousePrice()
                }));
            }
            filteredHouses = await _houseService.GetFilteredHouses(filterModel.Name, filterModel.Street,
                                                                   filterModel.Price, filterModel.Type);

            return(View("HousesSection", new HousesSectionViewModel()
            {
                Houses = _mapper.Map <IEnumerable <SectionHouseViewModel> >(filteredHouses),
                HousesMaxPrice = await _houseService.GetMaxHousePrice(),
                HousesMinPrice = await _houseService.GetMinHousePrice()
            }));
        }