コード例 #1
0
        /// <summary>
        /// Gets all the scheduled content where the content is scheduled after datetime.now
        /// </summary>
        /// <returns>Future content, sorted by beacon</returns>
        public IEnumerable <BeaconAvailability> GetFutureScheduledContent()
        {
            // This is a complex query, so need to draw on beacon and content data
            List <BeaconAvailability> beaconAvailability = new List <BeaconAvailability>();

            using (var db = new ApplicationDbContext())
            {
                foreach (var beacon in db.Beacons)
                {
                    var availability = new BeaconAvailability();
                    availability.BeaconId     = beacon.Id;
                    availability.FriendlyName = beacon.FriendlyName;
                    availability.Location     = beacon.Location;
                    availability.Bookings     = db.ScheduledItems.Where(item => item.BeaconId == beacon.Id && item.EndDateTime >= DateTime.Now)
                                                .Select(b => new BeaconBooking()
                    {
                        Start       = b.StartDateTime,
                        End         = b.EndDateTime,
                        Description = db.Content.FirstOrDefault(c => c.Id == b.ContentId).Title,
                        ContentId   = b.ContentId
                    }).ToList();

                    beaconAvailability.Add(availability);
                }
            }

            return(beaconAvailability);
        }
コード例 #2
0
        private static IList <Timeslot> PopulateWeeksForBeacon(BeaconAvailability beaconAvailability, DateTime startTime)
        {
            var      slots       = new List <Timeslot>();
            DateTime currentDate = startTime;

            while (currentDate < DateTime.Now.AddMonths(3))
            {
                Timeslot newTimeslot = new Timeslot();
                newTimeslot.Start = currentDate;
                newTimeslot.End   = currentDate.AddDays(7);
                newTimeslot.Unit  = TimeslotUnit.Weeks;

                // Select bookings which start or end in this period
                newTimeslot.Bookings = beaconAvailability.Bookings.Where(b =>
                                                                         (b.Start >= newTimeslot.Start && b.Start < newTimeslot.End) ||
                                                                         (b.End > newTimeslot.Start && b.End <= newTimeslot.End)).Select(booking => new TimeslotBooking()
                {
                    ContentId    = booking.ContentId,
                    ContentTitle = booking.Description
                }).ToList();
                newTimeslot.Timeslots = PopulateDaysOfWeekForBeacon(beaconAvailability, currentDate.Date, currentDate.AddDays(7).Date);

                currentDate = currentDate.AddDays(7);
                slots.Add(newTimeslot);
            }

            return(slots);
        }
コード例 #3
0
        private static IList <Timeslot> PopulateHoursOfDayForBeacon(BeaconAvailability beaconAvailability, DateTime startDate, DateTime endTime)
        {
            var slots       = new List <Timeslot>();
            var currentDate = startDate;

            while (currentDate < endTime)
            {
                Timeslot newTimeslot = new Timeslot();
                newTimeslot.Start    = currentDate;
                newTimeslot.End      = currentDate.AddHours(1);
                newTimeslot.Unit     = TimeslotUnit.Hours;
                newTimeslot.Bookings = beaconAvailability.Bookings.Where(b => b.Start >= newTimeslot.Start && b.End <= newTimeslot.End).Select(booking => new TimeslotBooking()
                {
                    ContentId    = booking.ContentId,
                    ContentTitle = booking.Description
                }).ToList();

                currentDate = currentDate.AddHours(1);
                slots.Add(newTimeslot);
            }

            return(slots);
        }