public JsonResult GetPropertiesCoordinates(PropertySearchViewModel model) { Array propertyCoordinates = null; propertyCoordinates = PropertyHelper.PopulateModelForPropertyCoordinates(model); return(Json(propertyCoordinates, JsonRequestBehavior.AllowGet)); }
//TODO get function to reload user id upon restart of application /* PropertiesController() * { * var userId = MiscellaneousHelper.getLoggedInUser(); * * if (!userId.Equals(new Guid())) * { * Session["userId"] = userId; * } * }*/ public ActionResult getProperties(PropertySearchViewModel model) { model.take = 1; model.PgNo = model.PgNo > 0 ? model.PgNo - 1 : 0;//this is done to since page number should start at 0 List <FeaturedPropertiesSlideViewModel> featuredPropertiesSlideViewModelList = null; featuredPropertiesSlideViewModelList = PropertyHelper.PopulatePropertiesViewModel(model); ViewBag.activeNavigation = PropertyHelper.mapPropertyCategoryCodeToName(model.PropertyCategory); ViewBag.searchViewModel = model; ViewBag.fetchAmount = model.take; ViewBag.pageNumber = model.PgNo + 1; return(View(featuredPropertiesSlideViewModelList)); }
/// <summary> /// Retrieves the coordinates of properties based on conditions /// </summary> /// <param name="model"></param> /// <returns></returns> public static Array PopulateModelForPropertyCoordinates(PropertySearchViewModel model) { Array propertyCoordinates = null; using (EasyFindPropertiesEntities dbCtx = new EasyFindPropertiesEntities()) { UnitOfWork unitOfWork = new UnitOfWork(dbCtx); List <Core.Filter> filters = createFilterList(model, unitOfWork); var deleg = ExpressionBuilder.GetExpression <Property>(filters); propertyCoordinates = unitOfWork.Property.FindPropertiesCoordinates(deleg); } return(propertyCoordinates); }
public IActionResult Search(PropertySearchViewModel model) { if (!ModelState.IsValid) { return(View("Index", model)); } var requirements = new Requirements { MaxBedrooms = model.MaxBedrooms, MinBedrooms = model.MinBedrooms, MaxPrice = model.MaxPrice, MinPrice = model.MinPrice, DistanceFromPostcode = model.DistanceFromPostcode, Postcode = model.Postcode }; model.Properties = _propertyRepository.GetProperties(requirements); return(View("Index", model)); }
/// <summary> /// Create a filter list to be used for property searching purposes /// </summary> /// <param name="model"></param> /// <param name="unitOfWork"></param> /// <returns></returns> private static List <Core.Filter> createFilterList(PropertySearchViewModel model, UnitOfWork unitOfWork) { List <Core.Filter> filters = new List <Core.Filter>(); //country if (!string.IsNullOrEmpty(model.Country)) { Core.Filter filter = new Core.Filter() { PropertyName = "Country", Operation = Op.Equals, Value = model.Country }; filters.Add(filter); } //division if (!string.IsNullOrEmpty(model.Division)) { Core.Filter filter = new Core.Filter() { PropertyName = "Division", Operation = Op.Equals, Value = model.Division }; filters.Add(filter); } //property category if (!string.IsNullOrEmpty(model.PropertyCategory)) { Core.Filter filter = new Core.Filter() { PropertyName = "CategoryCode", Operation = Op.Equals, Value = model.PropertyCategory }; filters.Add(filter); } //property type if (!string.IsNullOrEmpty(model.PropertyType)) { Core.Filter filter = new Core.Filter() { PropertyName = "TypeID", Operation = Op.Equals, Value = unitOfWork.PropertyType.GetPropertyTypeIDByName(model.PropertyType) }; filters.Add(filter); } //property purpose if (!string.IsNullOrEmpty(model.PropertyPurpose)) { Core.Filter filter = new Core.Filter() { PropertyName = "PurposeCode", Operation = Op.Equals, Value = PropertyHelper.mapPropertyPurposeNameToCode(model.PropertyPurpose) }; filters.Add(filter); } //price range if (model.MinPrice >= 0 && model.MaxPrice > 0) { Core.Filter filter1 = new Core.Filter() { PropertyName = "Price", Operation = Op.GreaterThanOrEqual, Value = model.MinPrice }; Core.Filter filter2 = new Core.Filter() { PropertyName = "price", Operation = Op.LessThanOrEqual, Value = model.MaxPrice }; filters.Add(filter1); filters.Add(filter2); } ///////////////TODO implement Or conditions for these/////////////////////// //ad type if (!String.IsNullOrEmpty(model.RdoAdType)) { Core.Filter filter = new Core.Filter() { PropertyName = "AdTypeCode", Operation = Op.Equals, Value = mapPropertyAdTypeNameToCode(model.RdoAdType) }; filters.Add(filter); } return(filters); }
public static List <FeaturedPropertiesSlideViewModel> PopulatePropertiesViewModel(PropertySearchViewModel model) { List <FeaturedPropertiesSlideViewModel> featuredPropertiesSlideViewModelList = new List <FeaturedPropertiesSlideViewModel>(); IEnumerable <Property> filteredProperties = null; IEnumerable <Property> searchTermProperties = null; IEnumerable <Property> properties = null; EasyFindPropertiesEntities dbCtx = new EasyFindPropertiesEntities(); //using (EasyFindPropertiesEntities dbCtx = new EasyFindPropertiesEntities()) //{ UnitOfWork unitOfWork = new UnitOfWork(dbCtx); List <Core.Filter> filters = createFilterList(model, unitOfWork); var deleg = ExpressionBuilder.GetExpression <Property>(filters); filteredProperties = unitOfWork.Property.FindProperties(deleg, model.take, model.PgNo); searchTermProperties = unitOfWork.Property.FindPropertiesBySearchTerm(model.SearchTerm, model.take, model.PgNo); properties = filteredProperties.Concat(searchTermProperties).Distinct(); //TODO optimize by removing extra calls to the database //this could be done via a single query foreach (var property in properties) { IEnumerable <int> avgPropRatings = unitOfWork.PropertyRating.GetPropertyRatingsCountByPropertyId(property.ID); featuredPropertiesSlideViewModelList.Add(new FeaturedPropertiesSlideViewModel() { property = property, owner = property.Owner, propertyImageURLs = null, propertyPrimaryImageURL = unitOfWork.PropertyImage.GetPrimaryImageURLByPropertyId(property.ID), averageRating = avgPropRatings.Count() > 0 ? (int)avgPropRatings.Average() : 0 }); } // } return(featuredPropertiesSlideViewModelList); }