protected override void Configure()
        {
            CreateMap <BL.Model.Place, DL.Place>()
            .ForMember(dest => dest.GeoPoint, opt => opt.MapFrom(src => GeographyHelper.PointFromGeoPoint(src.GeoLocation)))
            .ForMember(dest => dest.Offer, opt => opt.Ignore())
            .ForMember(dest => dest.AspNetUsers, opt => opt.Ignore());
            CreateMap <DL.Place, BL.Model.Place>()
            .ForMember(dest => dest.GeoLocation, opt => opt.MapFrom(src => new BL.Model.Geolocation((double)src.GeoPoint.Latitude,
                                                                                                    (double)src.GeoPoint.Longitude)));

            CreateMap <BL.Model.Offer, DL.Offer>()
            .ForMember(dest => dest.OfferTransactions, opt => opt.Ignore())
            .ForMember(dest => dest.Place, opt => opt.Ignore());
            CreateMap <DL.Offer, BL.Model.Offer>()
            .ForMember(dest => dest.AvailableAmount, opt => opt.Ignore());

            CreateMap <BL.Model.OfferTransaction, DL.OfferTransactions>()
            .ForMember(dest => dest.TypeId, opt => opt.MapFrom(src => (int)src.Type))
            .ForMember(dest => dest.OfferTransactionType, opt => opt.Ignore())
            .ForMember(dest => dest.AspNetUsers, opt => opt.Ignore())
            .ForMember(dest => dest.AspNetUsers1, opt => opt.Ignore())
            .ForMember(dest => dest.Offer, opt => opt.Ignore())
            .ForMember(dest => dest.PointTransactions, opt => opt.Ignore())
            .ForMember(dest => dest.UserOfferDelivery, opt => opt.Ignore());

            CreateMap <BL.Model.PointTransaction, DL.PointTransactions>()
            .ForMember(dest => dest.TypeId, opt => opt.MapFrom(src => (int)src.Type))
            .ForMember(dest => dest.AspNetUsers, opt => opt.Ignore())
            .ForMember(dest => dest.AspNetUsers1, opt => opt.Ignore())
            .ForMember(dest => dest.PointTransactionType, opt => opt.Ignore())
            .ForMember(dest => dest.OfferTransactions, opt => opt.Ignore());
        }
Ejemplo n.º 2
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());
        }
Ejemplo n.º 3
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());
        }