public IEventDetails GetEventDetails(ObjectId eventId)
        {
            try
            {
                var anEvent = _eventRepository.GetWithId(eventId);
                var invited = new List <SpotUser>();
                anEvent.Invited.ForEach(user => invited.Add(_userRepository.GetWithId(user) as SpotUser));

                var spot     = _spotRepository.GetWithId(anEvent.SpotId);
                var location = _locationRepository.GetWithId(spot.LocationId);
                var business = _businessRepository.GetWithId(location.BusinessId);

                return(new EventDetailsViewModel
                {
                    Id = anEvent.Id,
                    Title = anEvent.Title,
                    Description = anEvent.Description,
                    StartDatetime = anEvent.StartDateTime.ToLocalTime().ToString(DateService.GetBasicDateTimeFormat),
                    EndDatetime = anEvent.EndDateTime.ToLocalTime().ToString(DateService.GetBasicDateTimeFormat),
                    Invited = invited,
                    SpotId = spot.Id,
                    SpotName = spot.Name,
                    Location = location.FullAddress,
                    BusinessId = business.Id,
                    BusinessName = business.Name
                });
            }
            catch (Exception)
            {
                throw new Exception("Failed to perform atomic action GetEventDetails - " + Desc);
            }
        }
        public IEnumerable <ISpot> GetSpotObjects(string city, BsonDateTime starDateTime,
                                                  BsonDateTime endDateTime)
        {
            var allSpotIds = _locationRepository.GetSpotIdsInCity(city).ToList();
            //todo should be moved and changed
            //var occupiedSpots = _eventRepository.GetOccupiedSpotIds(city, starDateTime, endDateTime);
            //occupiedSpots.ForEach(s => allSpotIds.Remove(s));

            var spots = new List <ISpot>();

            foreach (var spotId in allSpotIds)
            {
                var spot = _spotRepository.GetWithId(spotId);
                //
                if (!IsSpotAvaible(starDateTime, endDateTime, spot))
                {
                    continue;
                }

                if (IsSpotOccupied(spot, starDateTime, endDateTime))
                {
                    continue;
                }

                var isSpotVisible = IsSpotVisible(spot);
                if (!isSpotVisible)
                {
                    var location = _locationRepository.GetWithId(spot.LocationId);
                    var business = _businessRepository.GetWithId(location.BusinessId);
                    var user     = _spotUserRepository.GetCurrent;

                    if (!IsUserBusinessMember(user.Email, business))
                    {
                        continue;
                    }
                    if (CanUserViewSpot(user, business) == false)
                    {
                        continue;
                    }

                    spots.Add(spot);
                    continue;
                }

                spots.Add(spot);
            }
            return(spots);
        }
        public ISpot GetSpotDetails(string id)
        {
            try
            {
                var spot      = _spotRepository.GetWithId(id);
                var isVisible = _spotCore.IsSpotVisible(spot);

                if (isVisible)
                {
                    return(spot);
                }

                var location = _locationRepository.GetWithId(spot.LocationId);
                var business = _businessRepository.GetWithId(location.BusinessId);
                var user     = _spotUserRepository.GetCurrent;

                var isUserBusinessMember = _spotCore.IsUserBusinessMember(user.Email, business);
                if (isUserBusinessMember == false)
                {
                    return(null);
                }

                var canView = _spotCore.CanUserViewSpot(user, business);
                return(canView ? spot : null);
            }
            catch
            {
                throw new NotImplementedException();
            }
        }
Esempio n. 4
0
        public IEnumerable <string> GetAddressesFromSpots(IEnumerable <ObjectId> spotIds)
        {
            var addresses = new HashSet <string>();

            foreach (var spotId in spotIds)
            {
                var locationId = _spotRepository.GetWithId(spotId).LocationId;
                var location   = _locationRepository.GetWithId(locationId);

                addresses.Add(location.FullAddress);
            }

            //todo: store cardinality of each record (e.g. Jernbanegade 12A : 5)
            return(addresses);
        }
Esempio n. 5
0
        private List <ITimelineEvent> GetFutureEventsSearch(
            int toTake, int toSkip, int intervalStart, int intervalEnd, IEnumerable <ISpotUser> users, List <ITimelineEvent> events)
        {
            if (toTake <= 0)
            {
                return(events);
            }

            var spotUsers = users as ISpotUser[] ?? users.ToArray();

            foreach (var user in spotUsers)
            {
                var userEvents = user.MyEvents;
                if (userEvents.IsNullOrEmpty())
                {
                    continue;
                }

                foreach (var userEvent in userEvents)
                {
                    if (toTake <= 0)
                    {
                        return(events);
                    }

                    if (IsDateInFutureInterval(userEvent.StartDateTime, intervalStart, intervalEnd) == false)
                    {
                        continue;
                    }

                    var anEvent = _eventRepository.GetWithId(userEvent.EventId);
                    if (anEvent.Visibility == false)
                    {
                        continue;
                    }

                    if (toSkip > 0)
                    {
                        toSkip--;
                        continue;
                    }

                    //Step 3 - create timeline event
                    var spot     = _spotRepository.GetWithId(anEvent.SpotId);
                    var location = _locationRepository.GetWithId(spot.LocationId);
                    var business = _businessRepository.GetWithId(location.BusinessId);

                    events.Add(new TimelineEventViewModel(user, anEvent, userEvent, spot, location, business));
                    toTake--;
                }
            }

            //Recurtion logic
            if (toTake <= 0)
            {
                return(events);
            }

            if (intervalEnd > 1000)
            {
                return(events);
            }

            //TODO: Adjust increment of end interval
            return(GetFutureEventsSearch(toTake, toSkip, intervalEnd, intervalEnd + 12, spotUsers, events));
        }