Пример #1
0
        //Get events nearby
        //Input: PointDTO, radius
        //Output: List of MapEventDTO
        public static List <MapEventDTO> GetEvents(PointDTO position, double radius)
        {
            SwapDbConnection   db             = new SwapDbConnection();
            PointDTO           point          = new PointDTO();
            List <Event>       Allevents      = db.Events.Where(e => e.end_date > DateTime.Now).ToList();
            List <MapEventDTO> FilteredEvents = new List <MapEventDTO>();

            foreach (Event e in Allevents)
            {
                point.lat = (double)e.place.latitude;
                point.lng = (double)e.place.longitude;
                if (PlaceService.GetDistance(point, position) <= radius)
                {
                    FilteredEvents.Add(new MapEventDTO
                    {
                        description   = e.place.description ?? "",
                        end_date      = e.end_date,
                        name          = e.place.name ?? "",
                        place_id      = e.place_id,
                        price         = e.price,
                        start_date    = e.start_date,
                        lat           = e.place.latitude,
                        lng           = e.place.longitude,
                        settlement    = e.place.settlement ?? "",
                        street        = e.place.street ?? "",
                        street_number = e.place.street_number ?? ""
                    });
                }
            }

            return(FilteredEvents);
        }
Пример #2
0
        //Get businesses nearby and filtered by categories
        //Input: PointDTO, CategoriesIdsDTO, radius
        //Output: List of MapBusinessDTO
        public static List <MapBusinessDTO> GetFilteredBusinessesAround(PointDTO position, CategoriesIdsDTO ids, double radius)
        {
            SwapDbConnection      db = new SwapDbConnection();
            PointDTO              point;
            List <business>       businesses;
            List <MapBusinessDTO> filteredBusinesses = new List <MapBusinessDTO>();
            main_category         mainCategory       = db.main_category.FirstOrDefault(category => category.main_id == ids.mainId);
            string iconCategory;

            if (mainCategory == null)
            {
                return(filteredBusinesses);
            }
            point      = new PointDTO();
            businesses = db.businesses.Include(b => b.products).Where(b => b.is_active &&
                                                                      b.approve_by_admin &&
                                                                      b.place.r_place_sub_and_main_category.Any(r => r.main_id == ids.mainId &&
                                                                                                                ids.subIds.Any(id => r.sub_id == id))).ToList();
            iconCategory = mainCategory.google_value;

            foreach (business b in businesses)
            {
                point.lat = (double)b.place.latitude;
                point.lng = (double)b.place.longitude;
                if (PlaceService.GetDistance(point, position) <= radius)
                {
                    filteredBusinesses.Add(new MapBusinessDTO
                    {
                        closing_hours = b.closing_hours,
                        description   = b.place.description,
                        lat           = b.place.latitude,
                        lng           = b.place.longitude,
                        name          = b.place.name ?? "",
                        opening_hours = b.opening_hours,
                        place_id      = b.place_id,
                        rating        = b.rating,
                        settlement    = b.place.settlement ?? "",
                        street        = b.place.street ?? "",
                        street_number = b.place.street_number ?? "",
                        icon          = iconCategory ?? "",
                        products      = b.products.Where(p => p.is_active && p.discount_end_date >= DateTime.Now).Select(product => new productDTO
                        {
                            business_id         = product.business_id,
                            creation_date       = product.creation_date,
                            description         = product.description,
                            discount            = product.discount,
                            discount_end_date   = product.discount_end_date,
                            discount_start_date = product.discount_start_date,
                            is_active           = product.is_active,
                            name       = product.name,
                            price      = product.price,
                            product_id = product.product_id
                        }).ToList()
                    });
                }
            }


            return(filteredBusinesses);
        }