private IQueryable <Listing> CreateQuery(ListingParameters p) { var query = Table.AsQueryable(); if (!string.IsNullOrEmpty(p.Neighbourhood)) { query = query.Where(l => l.NeighbourhoodCleansed == p.Neighbourhood); } if (p.PriceFrom.HasValue && p.PriceTo.HasValue) { query = query.Where(l => p.PriceFrom.Value <= l.Price && l.Price <= p.PriceTo.Value); } if (p.ReviewFrom.HasValue && p.ReviewTo.HasValue) { query = query.Where(l => p.ReviewFrom.Value <= l.ReviewScoresRating && l.ReviewScoresRating <= p.ReviewTo.Value); } if (p.Page.HasValue && p.PageSize.HasValue) { int skip = p.Page.Value * p.PageSize.Value - p.PageSize.Value; query = query.Skip(skip).Take(p.PageSize.Value); } return(query); }
public JsonResult GetCultures(ListingParameters listingParameters) { List <CultureInformationModel> cultureInformation = cultureBusiness.GetAllCultures(); List <CultureInformationVM> cultureInformationVM = new List <CultureInformationVM>(); Mapper.Map(cultureInformation, cultureInformationVM); Response <CultureInformationVM> response = new Response <CultureInformationVM>(); // response.TotalRecords = totalRecords; response.List = cultureInformationVM; return(Json(response, JsonRequestBehavior.AllowGet)); }
private async Task <FeatureCollection> GetListingsFeatureCollection(ListingParameters parameters) { var listings = await ListingRepository.Get(parameters); List <Feature> features = new(); FeatureCollection featureCollection = new(features); foreach (var listing in listings) { if (!listing.Latitude.HasValue || !listing.Longitude.HasValue) { continue; } features.Add(new Feature(new Point(new Position(listing.Latitude.Value, listing.Longitude.Value)), new { listing.Id })); } return(featureCollection); }
public async Task <IActionResult> Get([FromQuery] ListingParameters parameters) { if (parameters.Type == "geojson") { return(Ok(await GetListingsFeatureCollection(parameters))); } if (!parameters.Page.HasValue || !parameters.PageSize.HasValue) { return(Ok(await ListingRepository.Count(parameters))); } try { var listings = await ListingRepository.Get(parameters); return(Ok(listings)); } catch (SqlException) { return(BadRequest()); } }
public async Task <int> Count(ListingParameters p) { return(await CreateQuery(p).OrderBy(l => l.Name).CountAsync()); }
public async Task <IEnumerable <Listing> > Get(ListingParameters p) { return(await CreateQuery(p).OrderBy(l => l.Name).ToListAsync()); }