public ActionResult Index(PropertySearchModel searchModel, int page = 1) { ViewBag.CategoryList = _categoryEngine.GetAll(); var model = _propertyEngine.GetAll(searchModel).ToPagedList(page, 16); return(View(model)); }
public async Task <IActionResult> Properties(PropertySearchModel model) { var results = await _propertyDetailService.searchPropertyDetails(model); PropertyModel propertyModel = new PropertyModel(); List <PropertyDetailViewModel> details = new List <PropertyDetailViewModel>(); foreach (var item in results) { var propDetails = new PropertyDetailViewModel { Image = Convert.ToBase64String(item.PropertyImage?.FirstOrDefault().Image), Id = item.Id, NumOfbathrooms = item.NumOfbathrooms, NumOfBedrooms = item.NumOfBedrooms, LandSize = item.LandSize, NumOfGarages = item.NumOfGarages, NumOfKitchens = item.NumOfKitchens, NumOfParkingSpots = item.NumOfParkingSpots, NumOfReceptionRooms = item.NumOfReceptionRooms, PropertyAddress = item.PropertyAddress, PropertyDesc = item.PropertyDesc }; details.Add(propDetails); } propertyModel.PropertyDetails = details; propertyModel.propertySearch = new PropertySearchModel(); return(View(propertyModel)); }
public IHttpActionResult Get([FromUri] PropertySearchModel model) { var properties = _propertiesPresenter.GetProperties(model); var totalCount = properties.Count;; var totalPages = (int)Math.Ceiling((double)totalCount / model.PageSize); var urlHelper = new UrlHelper(Request); var prevLink = model.Page > 0 ? Url.Link("DefaultApi", new { controller = "Properties", page = model.Page - 1 }) : ""; var nextLink = model.Page < totalPages - 1 ? Url.Link("DefaultApi", new { controller = "Properties", page = model.Page + 1 }) : ""; var paginationHeader = new { TotalCount = totalCount, TotalPages = totalPages, PrePageLink = prevLink, NextPageLink = nextLink }; HttpContext.Current.Response.Headers.Add("X-Pagination", JsonConvert.SerializeObject(paginationHeader)); var results = properties .Skip(model.PageSize * model.Page) .Take(model.PageSize) .ToList(); //Results return(Ok(results)); }
public IQueryable <Property> GetAll(PropertySearchModel searchModel) { var result = _propertyRepository.GetAll(x => !x.IsDeleted); if (searchModel != null) { if (searchModel.Id.HasValue) { result = result.Where(x => x.Id == searchModel.Id); } if (!string.IsNullOrEmpty(searchModel.City)) { result = result.Where(x => x.City.Contains(searchModel.City)); } if (!string.IsNullOrEmpty(searchModel.Adress)) { result = result.Where(x => x.GeoLocation.Address.Contains(searchModel.Adress)); } if (searchModel.PriceFrom.HasValue) { result = result.Where(x => x.Price >= searchModel.PriceFrom); } if (searchModel.PriceTo.HasValue) { result = result.Where(x => x.Price <= searchModel.PriceTo); } if (searchModel.TypeOfProperty <= 2) { if (searchModel.TypeOfProperty == 0) { result = result.Where(x => x.TypeOfProperty == false); } else { result = result.Where(x => x.TypeOfProperty == true); } } if (searchModel.Status <= 2) { result = result.Where(x => x.Status == searchModel.Status); } if (searchModel.CategoryId != 0) { result = result.Where(x => x.Category.Id == searchModel.CategoryId); } } return(result); }
public async Task <ActionResult> Search() { var model = new PropertySearchModel(); model.PropertyTypesList = (await db.PropertyTypes.Convert(db)).ToList(); model.PropertyTypesList.Add(new SelectListItem() { Text = "", Value = null, Selected = true }); return(View(model)); }
// GET: User public ActionResult Index(PropertySearchModel m, int?_pageNo) { ViewBag.PropertyTypeId = new SelectList(db.PropertyTypes, "Id", "Ad"); //return RedirectToAction("Action", new { id = 99 }); var model = GetProducts(m); return(View(model.ToList())); }
public IQueryable <Property> GetProducts(PropertySearchModel searchModel) { var result = db.Properties.AsQueryable(); if (searchModel != null) { if (searchModel.MinPrice.HasValue) { result = result.Where(x => x.Price > searchModel.MinPrice); } if (searchModel.MaxPrice.HasValue) { result = result.Where(x => x.Price < searchModel.MaxPrice); } if (!String.IsNullOrWhiteSpace(searchModel.Adress)) { result = result.Where(x => x.Adress.Contains(searchModel.Adress)); } if (searchModel.SquareMeter.HasValue) { result = result.Where(x => x.SquareMeter == searchModel.SquareMeter); } if (searchModel.LivingRoomCount.HasValue) { result = result.Where(x => x.LivingRoomCount == searchModel.LivingRoomCount); } if (searchModel.NumberOfFloors.HasValue) { result = result.Where(x => x.NumberOfFloors == searchModel.NumberOfFloors); } if (searchModel.PropertyTypeId.HasValue) { result = result.Where(x => x.PropertyTypeId == searchModel.PropertyTypeId); } if (searchModel.RoomCount.HasValue) { result = result.Where(x => x.RoomCount == searchModel.RoomCount); } if (searchModel.State != State.Empty) { result = result.Where(x => x.State == searchModel.State); } if (searchModel.WarmingType != WarmingType.Empty) { result = result.Where(x => x.WarmingType == searchModel.WarmingType); } if (searchModel.Floor != searchModel.Floor) { result = result.Where(x => x.Floor == searchModel.Floor); } } return(result); }
public IList <PropertyModel> GetProperties(PropertySearchModel model) { var properties = _service.GetProperties(new SearchModel() { Address = model.Adsress, Id = model.Id, PriceMax = model.PriceMax, PriceMin = model.PriceMin }); return(properties.Select(x => new PropertyModel() { Address = x.Address, Id = x.Id, Name = x.Name, Price = x.Price, PropertyDescription = x.PropertyDescription }).ToList()); }
public async Task <IEnumerable <PropertyModel> > GetByQueryAsync(PropertySearchModel searchModel) { Uri url = new Uri($"properties?{searchModel.GetQueryParameter()}", UriKind.Relative); var response = await _apiGateway.ExecuteRequest <List <PropertyApiResponse> >(HttpClientNames.Properties, url); if (!response.IsSuccess) { _logger.LogError($"Call to {url} failed with {response.Status}"); throw new ApiException(response.Status, Resources.PropertiesFailure); } return(response.Content.ToDomain()); }
public async Task SendsRequestBySearch() { // Arrange var stubData = BuildResponse(StubPropertyApiResponse().Generate(5)); _apiGatewayMock.Setup(gw => gw.ExecuteRequest <List <PropertyApiResponse> >(It.IsAny <string>(), It.IsAny <Uri>())).ReturnsAsync(stubData); PropertySearchModel searchModel = new PropertySearchModel { }; // Act var result = await _classUnderTest.GetByQueryAsync(searchModel); // Assert result.Should().HaveCount(stubData.Content.Count); }
public async Task <PropertySearchModel> GetProperties(PropertySearchModel model) { var url = ODataApiUri + "/Property?" + GetFilterString(model); var result = await GetOdataResultFromApi(url); var searchResultCount = 0; if (result.Count != null) { int.TryParse(result.Count.ToString(), out searchResultCount); } model.TotalRows = searchResultCount; model.PropertySearchResult.Clear(); model.PropertySearchResult.AddRange(result.Items.Select(item => JsonConvert.DeserializeObject <PropertyDto>(item.ToString()))); return(model); }
public async Task <IActionResult> ListProperties([FromQuery] string address, [FromQuery] string postcode, [FromQuery] string q) { PropertySearchModel searchModel = new PropertySearchModel { Address = address, PostCode = postcode, Query = q }; _logger.LogInformation(Resources.ListingProperties); var properties = await _listPropertiesUseCase.ExecuteAsync(searchModel); List <PropertyListItem> response = properties.ToResponse(); _logger.LogInformation(Resources.FoundProperties, response.Count); return(Ok(response)); }
public async Task ReturnsProperties() { // Arrange int expectedPropertyCount = 5; SetupProperties(expectedPropertyCount); PropertySearchModel searchModel = new PropertySearchModel { Query = "DummyQuery" }; // Act var result = await _classUnderTest.ExecuteAsync(searchModel); // Assert result.Should().HaveCount(expectedPropertyCount); }
public async Task <IEnumerable <PropertyDetail> > searchPropertyDetails(PropertySearchModel searchModel) { using (var context = new PropertyManagementContext(_dbContextOptions)) { var result = context.PropertyDetail.Include(x => x.PropertyImage).Include(x => x.OwnerHistory).AsQueryable(); if (searchModel != null) { if (!string.IsNullOrEmpty(searchModel.OwnerName)) { bool containsOwner = false; foreach (var item in result) { var owners = item.OwnerHistory.Select(x => x.OwnerName); foreach (var owner in owners) { if (owner.Contains(searchModel.OwnerName)) { containsOwner = true; } } result = (!containsOwner) ? result.Where(y => y.Id != item.Id): result; } } if (!string.IsNullOrEmpty(searchModel.Address)) { result = result.Where(x => x.PropertyAddress.Contains(searchModel.Address)); } if (searchModel.NumOfBedrooms.HasValue && searchModel.NumOfBedrooms.Value != 0) { result = result.Where(x => x.NumOfBedrooms == searchModel.NumOfBedrooms); } if (searchModel.NumOfBathrooms.HasValue && searchModel.NumOfBathrooms.Value != 0) { result = result.Where(x => x.NumOfbathrooms == searchModel.NumOfBathrooms); } } return(await result?.ToListAsync()); } }
private string GetFilterString(PropertySearchModel searchModel) { var filterString = string.Empty; if (searchModel != null) { if (!string.IsNullOrWhiteSpace(searchModel.FilterText)) { if (string.IsNullOrWhiteSpace(filterString)) { filterString = ODataFilterConstant.Filter + $"contains(Person/Forename,'{searchModel.FilterText}') eq true"; } else { filterString += $" or contains(Person/Forename,'{searchModel.FilterText}') eq true"; } filterString += $" or contains(Person/Surname,'{searchModel.FilterText}') eq true"; } AddPageSizeNumberAndSortingInFilterString(searchModel, ref filterString); } return(filterString); }
public async Task <ActionResult> SearchIndex(PropertySearchModel searchModel) { if (searchModel != null) { var result = from prop in db.Propertys where ((prop.Title.Contains(searchModel.SearchTerm) || prop.Description.Contains(searchModel.SearchTerm)) || string.IsNullOrEmpty(searchModel.SearchTerm)) && (prop.Address.County.Contains(searchModel.County) || string.IsNullOrEmpty(searchModel.County)) && (prop.Price >= (searchModel.PriceFrom ?? double.MinValue) && prop.Price <= (searchModel.PriceTo ?? double.MaxValue)) && ((prop.NumberOfBedrooms >= (searchModel.NumberOfBedroomsFrom ?? int.MinValue)) && (prop.NumberOfBedrooms <= (searchModel.NumberOfBedroomsTo ?? int.MaxValue))) && (prop.PropertyTypeId == (searchModel.PropertyTypeId ?? prop.PropertyTypeId)) select prop; var properties = await result.ToListAsync(); var model = await properties.Convert <PropertyModel>(db); return(View(model.OrderBy(t => t.Price))); } return(View()); }
public object Search(PropertySearchModel search) { List <Property> properties = db.Properties.ToList(); if (search.Keyword != null) { properties = properties.Where(i => i.Title.Contains(search.Keyword)).ToList(); } if (search.Province != null) { properties = properties.Where(i => i.Province.ToLower() == search.Province.ToLower()).ToList(); } if (search.Status != null) { properties = properties.Where(i => i.Status.ToLower() == search.Status.ToLower()).ToList(); } if (search.MinBeds != null) { properties = properties.Where(i => i.Bedrooms >= search.MinBeds).ToList(); } if (search.MaxBeds != null) { properties = properties.Where(i => i.Bedrooms <= search.MaxBeds).ToList(); } if (search.MinBaths != null) { properties = properties.Where(i => i.Bathrooms >= search.MinBaths).ToList(); } if (search.MaxBaths != null) { properties = properties.Where(i => i.Bathrooms <= search.MaxBaths).ToList(); } if (search.MinArea != null) { properties = properties.Where(i => i.Size >= search.MinArea).ToList(); } if (search.MaxArea != null) { properties = properties.Where(i => i.Size <= search.MaxArea).ToList(); } if (search.MinPrice != null) { properties = properties.Where(i => i.Price >= search.MinPrice).ToList(); } if (search.MaxPrice != null) { properties = properties.Where(i => i.Price <= search.MaxPrice).ToList(); } return(properties); }
public async Task <IEnumerable <PropertyDetail> > searchPropertyDetails(PropertySearchModel searchModel) { return(await _propertyDetailRepository.searchPropertyDetails(searchModel)); }
// A function that inserts a User into the database. public void InsertPropertySearch(PropertySearchModel newPropertySearch) { // Declare a new variable. Variable name is ‘sSQL’. Datatype is ‘string’. string sSQL = ""; // Define the value for the ‘sSQL’ string variable. // Notice that this text is a SQL Query. sSQL += " INSERT INTO [Property Search] "; // More columns will need to be added, depending on how many columns you have in your User table. // In this line, you need ALL the columns from your User table. // The word ‘Password’ is in brackets because it is a reserved word in SQL. // We are hijacking that word and using it for our own purposes, so we need to put it in brackets. // Normally, SQL would try to interpret the word 'Password' differently than how we're using it. sSQL += " (PropertyName, PropertyAddress, PropertyCity, PropertyState, PropertyZIP, PropertyTownship, PropertyCounty,PropertyStatus) "; sSQL += " Values "; // The ‘@’ sign is a SQL Variable. It is connected to a SqlParameter (below). // This line needs to exactly match the list of columns in the User table. sSQL += " (@PropertyName, @PropertyAddress, @PropertyCity, @PropertyState, @PropertyZIP, @PropertyTownship, @PropertyCounty, @PropertyStatus) "; // Declare a new variable. Variable name is ‘sqlcomm’. Datatype is ‘SqlCommand’. SqlCommand sqlcomm = new SqlCommand(); // Assign a value to the CommandText property. sqlcomm.CommandText = sSQL; // This SqlParameter constructor takes two arguments as input values. // Argument One: SQL Variable Name // Argument Two: Variable Value // The SqlParameter handles the declaration of the actual SQL Parameter in the T-SQL. SqlParameter sqlparam = new SqlParameter("PropertyName", newPropertySearch.PropertyName); sqlcomm.Parameters.Add(sqlparam); // Notice that there is one ‘SqlParameter’ variable for each variable used in the SQL Query // More SqlParameter variables will need to be added for additional SQL variables. sqlparam = new SqlParameter("PropertyAddress", newPropertySearch.PropertyAddress); sqlcomm.Parameters.Add(sqlparam); sqlparam = new SqlParameter("PropertyCity", newPropertySearch.PropertyCity); sqlcomm.Parameters.Add(sqlparam); sqlparam = new SqlParameter("PropertyState", newPropertySearch.PropertyState); sqlcomm.Parameters.Add(sqlparam); sqlparam = new SqlParameter("PropertyZIP", newPropertySearch.PropertyZIP); sqlcomm.Parameters.Add(sqlparam); sqlparam = new SqlParameter("PropertyTownship", newPropertySearch.PropertyTownship); sqlcomm.Parameters.Add(sqlparam); sqlparam = new SqlParameter("PropertyCounty", newPropertySearch.PropertyCounty); sqlcomm.Parameters.Add(sqlparam); sqlparam = new SqlParameter("PropertyStatus", newPropertySearch.PropertyStatus); sqlcomm.Parameters.Add(sqlparam); // Execute the query. ExecNonQuery(sqlcomm); }
public async Task <PropertySearchModel> GetProperties(PropertySearchModel model) { return(await _propertyApiClient.GetProperties(model)); }