public ActionResult TenantSearch(TenantSearchViewModel model) { TenantSearchAndDetailViewModel result = new TenantSearchAndDetailViewModel { TenantSearchViewModel = model }; result.TenantList = _userService.TenantSearch(result.TenantSearchViewModel); FillLocInfo(result.TenantSearchViewModel); Session["TenantSearchModel"] = model; return(View(result)); }
private void FillLocInfo(TenantSearchViewModel model) { model.Countries = _locationService.GetCountries(); model.Locationlevel1 = new List <SelectListItem>(); foreach (var country in model.Countries) { var states = _locationService.GetLocationLevel1(country.Id) .Select(c => new SelectListItem { Value = c.Id.ToString(), Text = $"({country.Name.Substring(0, 2).ToUpper()}) - {c.Name}" }) .ToList(); model.Locationlevel1.AddRange(states); } }
public List <ClientSummaryViewModel> TenantSearch(TenantSearchViewModel model) { var selectedEmploymentStatuses = model.EmploymentStatusViewModel.Where(c => c.Selected).Select(c => c.EmploymentStatus).ToList(); var slectedLocation = model.Locations.SelectMany(s => s.Children).SingleOrDefault(c => c.Selected); int?selectedLocationId = slectedLocation?.Id; IQueryable <SearchProfileListing> query = _dbContext.SearchProfiles .Where(s => model.Price == null || (s.PriceRange.From <= model.Price) && (s.PriceRange.To >= model.Price)) .Where(spl => selectedLocationId == null || spl.Locations.Any(l => l.LocationId == selectedLocationId)); #region Residence filter if (model.SelectedPropertyType != PropertyType.Land) { query = query.OfType <SearchProfileResidence>() .Where(c => model.LivingArea == null || (c.ResidentialArea.From <= model.LivingArea) && (c.ResidentialArea.To >= model.LivingArea)) .Where(c => model.NumberOfLivingRooms == null || (c.NumberOfLivingRooms.From <= model.NumberOfLivingRooms) && (c.NumberOfLivingRooms.To >= model.NumberOfLivingRooms)); } #endregion List <ClientSummaryViewModel> clients = null; if (model.SelectedTypeOfMerchandising == TypeOfMerchandising.Sale) { if (model.SelectedPropertyType == PropertyType.House) { query = query.OfType <SearchProfileHouseForSale>(); } if (model.SelectedPropertyType == PropertyType.Flat) { query = query.OfType <SearchProfileFlatForSale>(); } } if (model.SelectedTypeOfMerchandising == TypeOfMerchandising.Rent) { query = from searchProfile in query from client in searchProfile.Clients join agent in _dbContext.Agents on client.SearchProfile.UserId equals agent.UserId where (client.Income + ((client.Persons.Sum(d => d.Income) == null) ? 0 : (client.Income + client.Persons.Sum(d => d.Income))) >= model.MinIncome) && (selectedEmploymentStatuses.Count == 0 || selectedEmploymentStatuses.Any(es => es == client.EmploymentStatus)) && model.MaxNumberOfMembers == null || (client.Persons.Count < model.MaxNumberOfMembers) select searchProfile; if (model.SelectedPropertyType == PropertyType.House) { query = from searchProfile in query.OfType <SearchProfileHouseForRent>() where (model.PetsAreAllowed || searchProfile.IsPetsAllowed == model.PetsAreAllowed) && (model.IsSmokingAllowed || searchProfile.IsSmokingAllowed == model.IsSmokingAllowed) select searchProfile; } else if (model.SelectedPropertyType == PropertyType.Flat) { query = from searchProfile in query.OfType <SearchProfileFlatForRent>() from client in searchProfile.Clients where (model.PetsAreAllowed || searchProfile.IsPetsAllowed == model.PetsAreAllowed) && (model.IsSmokingAllowed || searchProfile.IsSmokingAllowed == model.IsSmokingAllowed) select searchProfile; } } clients = (from searchProfile in query.OfType <SearchProfileResidence>() from client in searchProfile.Clients join agent in _dbContext.Agents on client.SearchProfile.UserId equals agent.UserId select new ClientSummaryViewModel { Name = agent.User.FirstName + " " + agent.User.LastName, ClientId = client.Id, UserId = client.SearchProfile.UserId, Headline = client.Headline, Income = client.Income, About = client.About, PriceFrom = searchProfile.PriceRange.From, PriceTo = searchProfile.PriceRange.To, AreaFrom = searchProfile.ResidentialArea.From, AreaTo = searchProfile.ResidentialArea.To, NumberOfLivingRoomsFrom = searchProfile.NumberOfLivingRooms.From, NumberOfLivingRoomsTo = searchProfile.NumberOfLivingRooms.To, AvailableFrom = searchProfile.AvailableFrom, AvailableTo = searchProfile.AvailableTo, } ).ToList(); return(clients); }