public async Task <IActionResult> MatchCommercial([FromRoute] int?firmId, [FromBody] CommercialQuery query) { if (firmId == null) { return(await MatchCommercialProperty(query)); } else { return(await MatchCommercialPropertyByFirm((int)firmId, query)); } }
public async Task <IActionResult> MatchCommercialProperty([FromBody] CommercialQuery query) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } else { switch (query.purpose) { case Purpose.Rent: return(Ok(await _matchHelper.MatchCommercialRentalProperty(query))); case Purpose.Sale: return(Ok(await _matchHelper.MatchCommercialSaleProperty(query))); default: return(Ok(await _matchHelper.MatchCommercialRentalProperty(query))); } } }
public List <CommercialPropertyIndex> MatchCommercialProperty(CommercialQuery query, Purpose purpose, List <CommercialProperty> industrials) { List <CommercialPropertyIndex> indexedPropertyList = new List <CommercialPropertyIndex>(); switch (purpose) { case Purpose.Rent: industrials = industrials.Where(m => m.Purpose == Purpose.Rent).ToList(); industrials = industrials.Where(m => m.State.ToLower() == query.State.ToLower()).ToList(); foreach (var item in industrials) { double roomPoint = RoomRank(item.NumberOfBedrooms, query.NumberOfRooms); double pricePoint = PriceRank(item.Price, query.minPrice, query.maxPrice); var propertyIndex = new CommercialPropertyIndex() { Id = item.Id, ImageLink1 = item.ImageLink1, ImageLink2 = item.ImageLink2, ImageLink3 = item.ImageLink3, City = item.City, State = item.State, Name = item.Name, ProviderName = item.ProviderName, Price = item.Price, ParkingSpace = item.ParkingSpace, Area = item.Area, Purpose = item.Purpose, NumberOfBedrooms = item.NumberOfBedrooms, NeighbourhoodSecurity = item.NeighbourhoodSecurity, Extras = item.Extras, BuildingType = item.BuildingType, IsActive = item.IsActive }; propertyIndex.Rank = roomPoint + pricePoint; if (item.City.ToLower() == query.City.ToLower()) { propertyIndex.Rank = propertyIndex.Rank + locationScore; } indexedPropertyList.Add(propertyIndex); } return(indexedPropertyList); case Purpose.Sale: industrials = industrials.Where(m => m.Purpose == Purpose.Sale).ToList(); industrials = industrials.Where(m => m.State.ToLower() == query.State.ToLower()).ToList(); foreach (var item in industrials) { double roomPoint = RoomRank(item.NumberOfBedrooms, query.NumberOfRooms); double pricePoint = PriceRank(item.Price, query.minPrice, query.maxPrice); var propertyIndex = new CommercialPropertyIndex() { Id = item.Id, ImageLink1 = item.ImageLink1, ImageLink2 = item.ImageLink2, ImageLink3 = item.ImageLink3, City = item.City, State = item.State, Name = item.Name, ProviderName = item.ProviderName, Price = item.Price, ParkingSpace = item.ParkingSpace, Area = item.Area, Purpose = item.Purpose, NumberOfBedrooms = item.NumberOfBedrooms, NeighbourhoodSecurity = item.NeighbourhoodSecurity, Extras = item.Extras, BuildingType = item.BuildingType, IsActive = item.IsActive }; propertyIndex.Rank = roomPoint + pricePoint; if (item.City.ToLower() == query.City.ToLower()) { propertyIndex.Rank = propertyIndex.Rank + locationScore; } indexedPropertyList.Add(propertyIndex); } return(indexedPropertyList); default: break; } return(null); }
public async Task <IEnumerable <CommercialPropertyIndex> > MatchCommercialSalePropertyByFirm(int firmId, CommercialQuery query) { var propertyList = await _manager.GetActiveIndustrialPropertyByProvider(firmId); var result = _match.MatchCommercialProperty(query, Purpose.Sale, propertyList); string stringQuery = $"Number of rooms: {query.NumberOfRooms}. max price: {query.maxPrice}, min price: {query.minPrice}"; string location = $"{query.City}, {query.State}"; _manager.AddSearchQueryToLog(stringQuery, location, firmId, PropertyType.Commercial, result.Count, 0); return(result.OrderByDescending(m => m.Rank)); }