예제 #1
0
        public async Task <IList <PlaceInfo> > GetShortPlaceInAreaAsync(Geolocation geolocation, double radiusMetres, int limit)
        {
            var         radiusSm = radiusMetres * 1000;
            DbGeography area     = GeographyHelper.PointFromGeoPoint(geolocation).Buffer(radiusSm);

            var pointsQuery = (from place in _dbContext.Place
                               where SqlSpatialFunctions.Filter(place.GeoPoint, area) == true
                               select new { place.Id, place.GeoPoint, place.Name }).Take(limit);

            var points = await pointsQuery.ToListAsync();

            return(points.Select(t => new PlaceInfo(t.Id, t.Name, new Geolocation((double)t.GeoPoint.Latitude, (double)t.GeoPoint.Longitude))).ToList());
        }
예제 #2
0
        private async Task <IList <BL.Model.Offer> > GetOffersAsync(int?offerId, string ownerUserId, Area area, int?placeId, bool?isActive, int?minItemsAmount, int?limit)
        {
            #region query
            var query = from user in _dbContext.AspNetUsers
                        from place in user.Place
                        from offer in place.Offer
                        select new
            {
                User        = user,
                Place       = place,
                Offer       = offer,
                OfferAmount = offer.OfferTransactions.Select(t => t.Amount).DefaultIfEmpty(0).Sum()
            };

            if (area != null)
            {
                var         radiusSm = area.RadiusMeters * 100;
                DbGeography dbArea   = GeographyHelper.PointFromGeoPoint(area).Buffer(radiusSm);

                query = query.Where(t => SqlSpatialFunctions.Filter(t.Place.GeoPoint, dbArea) == true);
            }

            if (offerId != null)
            {
                query = query.Where(t => t.Offer.Id == offerId.Value);
            }

            if (!string.IsNullOrEmpty(ownerUserId))
            {
                query = query.Where(t => t.User.Id == ownerUserId);
            }

            if (placeId != null)
            {
                query = query.Where(t => t.Place.Id == placeId.Value);
            }

            if (isActive != null)
            {
                query = query.Where(t => t.Offer.IsActive == isActive.Value);
            }

            if (minItemsAmount != null)
            {
                query = query.Where(t => t.OfferAmount >= minItemsAmount.Value);
            }

            if (limit != null)
            {
                query = query.Take(limit.Value);
            }

            #endregion

            var dbOffers = await query.Select(t =>
                                              new
            {
                Id              = t.Offer.Id,
                Title           = t.Offer.Title,
                Description     = t.Offer.Description,
                Price           = t.Offer.Price,
                IsActive        = t.Offer.IsActive,
                PlaceId         = t.Offer.PlaceId,
                AvailableAmount = t.OfferAmount,
                LogoUrl         = t.Offer.LogoUrl
            }).ToListAsync().ConfigureAwait(false);

            var offers = dbOffers.Select(t => new BL.Model.Offer()
            {
                Id              = t.Id,
                Title           = t.Title,
                Description     = t.Description,
                Price           = t.Price,
                IsActive        = t.IsActive,
                PlaceId         = t.PlaceId,
                AvailableAmount = t.AvailableAmount,
                LogoUrl         = t.LogoUrl
            });

            return(offers.ToList());
        }