private async Task <DataAboutRealEstatesForRealtorView> PreparedDataAboutRealEstates(ChoosenSearchParametersForRealtorView choosenSearchParameters) { ChoosenSearchParametersForRealtorDTO choosenSearchParametersDTO = _mapper.Map <ChoosenSearchParametersForRealtorView, ChoosenSearchParametersForRealtorDTO> (choosenSearchParameters); string userId = HttpContext.User.Identity.GetUserId(); DataAboutRealEstatesForRealtorDTO dataForRealtor = await _realtorService.FormRealEstates(userId, choosenSearchParametersDTO); return(_mapper.Map <DataAboutRealEstatesForRealtorDTO, DataAboutRealEstatesForRealtorView>(dataForRealtor)); }
public void RealEstatePriceFilterWithEquelsBorderValue() { int filteredRealEstateAmount = 3; var searchParameters = new ChoosenSearchParametersForRealtorDTO() { PriceFrom = 36.000M, PriceTo = 56.000M }; var realEstate = _realtorService.GetRealEstatesForRealtor("", searchParameters).ToList(); Assert.IsTrue(realEstate.Count == filteredRealEstateAmount); }
public void RealEstatePriceFilter() { int filteredRealEstateAmount = 1; var searchParameters = new ChoosenSearchParametersForRealtorDTO() { PriceFrom = 50.000M, PriceTo = 60.000M }; var realEstate = _realtorService.GetRealEstatesForRealtor("", searchParameters).ToList(); Assert.IsTrue(realEstate.Count == filteredRealEstateAmount); }
private async Task <DataAboutRealEstatesForRealtorView> PreparedRealEstates(ChoosenSearchParametrsForRealtorView choosenSearchParameters) { ChoosenSearchParametersForRealtorDTO choosenSearchParametersDTO = _mapper.Map <ChoosenSearchParametrsForRealtorView, ChoosenSearchParametersForRealtorDTO> (choosenSearchParameters); string userId = HttpContext.User.Identity.GetUserId(); var users = await _identityService.GetUsers().ProjectTo <UserViewModel>(_mapper.ConfigurationProvider).ToListAsync(); List <RealEstateForRealtorDTO> realEstatesDTO = await _realtorService.GetRealEstatesForRealtor(userId, choosenSearchParametersDTO) .Skip((choosenSearchParameters.Page - 1) * _pageSize) .Take(_pageSize).ToListAsync(); List <RealEstateForRealtorView> realEstates = _mapper.Map <List <RealEstateForRealtorDTO>, List <RealEstateForRealtorView> >(realEstatesDTO); realEstates = realEstates.Join(users, r => r.RealtorId, u => u.Id, (r, u) => { r.RealtorName = u.Name; r.RealtorEmail = u.Email; return(r); }).ToList(); DataAboutRealEstatesForRealtorView dataForRealtor = new DataAboutRealEstatesForRealtorView { ChoosenSearchParametersForRealtor = choosenSearchParameters, RealEstates = realEstates, SearchParameters = _mapper.Map <DataForSearchParametersDTO, DataForSearchParametersRealtorView>(await _realtorService.InitiateSearchParameters()), PagingInfo = new PagingInfo { CurrentPage = choosenSearchParameters.Page, ItemsPerPage = _pageSize, TotalItems = await _realtorService.GetRealEstatesForRealtor(userId, choosenSearchParametersDTO).CountAsync() } }; return(dataForRealtor); }
public IQueryable <CityDistrictDTO> FilteredDistricts(IQueryable <CityDistrictDTO> districts, ChoosenSearchParametersForRealtorDTO parameters) { var result = districts; if (parameters.DistrictId.HasValue) { result = result.Where(x => x.Id == parameters.DistrictId); } return(result); }
public IQueryable <RealEstateDTO> FilteredRealEstates(IQueryable <RealEstateDTO> realEstates, ChoosenSearchParametersForRealtorDTO parameters, string userId) { var result = realEstates; if (parameters.RoomNumber.HasValue) { result = result.Where(x => x.RoomNumber == parameters.RoomNumber); } if (parameters.AreaFrom.HasValue) { result = result.Where(x => x.Area >= parameters.AreaFrom); } if (parameters.AreaTo.HasValue) { result = result.Where(x => x.Area <= parameters.AreaTo); } if (parameters.PriceFrom.HasValue) { result = result.Where(x => x.Price >= parameters.PriceFrom); } if (parameters.PriceTo.HasValue) { result = result.Where(x => x.Price <= parameters.PriceTo); } if (parameters.HeightFrom.HasValue) { result = result.Where(x => x.Height >= parameters.HeightFrom); } if (parameters.HeightTo.HasValue) { result = result.Where(x => x.Height <= parameters.HeightTo); } if (parameters.FloorFrom.HasValue) { result = result.Where(x => x.Floor >= parameters.FloorFrom); } if (parameters.FloorTo.HasValue) { result = result.Where(x => x.Floor <= parameters.FloorTo); } if (parameters.ShowOnlyMyOwn) { result = result.Where(x => x.RealtorId == userId); } return(result); }
public IQueryable <RealEstateForRealtorDTO> GetRealEstatesForRealtor(string userId, ChoosenSearchParametersForRealtorDTO parameters) { IQueryable <RealEstateForRealtorDTO> realEstates = (from realEstate in FilteredRealEstates(GetRealEstates(), parameters, userId) join street in GetStreets() on realEstate.StreetId equals street.Id join district in FilteredDistricts(GetKievDistricts(), parameters) on street.CityDistrictId equals district.Id select new RealEstateForRealtorDTO { Id = realEstate.Id, Building = realEstate.Building, Appartment = realEstate.Appartment, Floor = realEstate.Floor, Height = realEstate.Height, Area = realEstate.Area, Price = realEstate.Price, RoomNumber = realEstate.RoomNumber, CreationDate = realEstate.CreationDate, Description = realEstate.Description, IsSold = realEstate.IsSold, RealtorId = realEstate.RealtorId, StreetName = street.Name, DistrictName = district.Name, IsOwner = (userId == realEstate.RealtorId), Image = realEstate.Image, DistrictId = district.Id, StreetId = street.Id }); return(_realeEstateSort.Sort(parameters.SortOrder)(realEstates)); }
public async Task <DataAboutRealEstatesForRealtorDTO> FormRealEstates(string userId, ChoosenSearchParametersForRealtorDTO parameters) { IQueryable <RealEstateForRealtorDTO> realEstates = from realEstate in _filter.FilteredRealEstates(_realEstatesData.RealEstates(), parameters, userId) join street in _realEstatesData.Streets() on realEstate.StreetId equals street.Id join district in _filter.FilteredDistricts(_realEstatesData.KievDistricts(), parameters) on street.CityDistrictId equals district.Id join user in _realEstatesData.Users() on userId equals user.Id select new RealEstateForRealtorDTO { Id = realEstate.Id, Building = realEstate.Building, Appartment = realEstate.Appartment, Floor = realEstate.Floor, Height = realEstate.Height, Area = realEstate.Area, Price = realEstate.Price, RoomNumber = realEstate.RoomNumber, CreationDate = realEstate.CreationDate, Description = realEstate.Description, IsSold = realEstate.IsSold, RealtorId = realEstate.RealtorId, RealtorName = user.Name, RealtorEmail = user.Email, StreetName = street.Name, DistrictName = district.Name, IsOwner = (userId == realEstate.RealtorId), Image = realEstate.Image, DistrictId = district.Id, StreetId = street.Id }; IQueryable <RealEstateForRealtorDTO> result = _realeEstateSort.Sort(parameters.SortOrder)(realEstates); DataAboutRealEstatesForRealtorDTO dataForRealtor = new DataAboutRealEstatesForRealtorDTO { ChoosenSearchParametersForRealtor = parameters, RealEstates = await result.Skip((parameters.Page - 1) *_itemsOnPage).Take(_itemsOnPage).ToListAsync(), SearchParameters = await InitiateSearchParameters(), PagingInfo = new PagingInfoDTO { CurrentPage = parameters.Page, ItemsPerPage = _itemsOnPage, TotalItems = await result.CountAsync() } }; return(dataForRealtor); }