예제 #1
0
        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);
        }
예제 #2
0
        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));
        }
예제 #3
0
        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);
        }
예제 #4
0
        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());
            }
        }
예제 #5
0
 public async Task <int> Count(ListingParameters p)
 {
     return(await CreateQuery(p).OrderBy(l => l.Name).CountAsync());
 }
예제 #6
0
 public async Task <IEnumerable <Listing> > Get(ListingParameters p)
 {
     return(await CreateQuery(p).OrderBy(l => l.Name).ToListAsync());
 }