Ejemplo n.º 1
0
        //creates table for weekly bookings
        public WeeklyBookingTable GetWeeklyBookings(DateTime weekStartDate, string roomName)
        {
            List <WeeklyHeader> weekDays = WeekDays(weekStartDate);

            WeeklyBookingTable bookingTable = new WeeklyBookingTable();

            bookingTable.Rooms = bookingRepository.GetBookingRooms();
            bookingTable.Rows  = new List <BookingRow>();
            bookingTable.Today = weekStartDate;

            DateTime currentTime = weekStartDate.Date.AddHours(7);
            DateTime endTime     = weekStartDate.Date.AddHours(19);

            DateTime startOfWeek = weekStartDate.Date;                           //Assume Monday was passed in
            DateTime endOfWeek   = weekStartDate.Date.AddDays(7).AddSeconds(-1); //23.59 Sunday
            IEnumerable <Booking> weeklyRoomBookings = bookingRepository.GetBookingsForPeriod(startOfWeek, endOfWeek, roomName);

            int rowIndex             = 0;
            var skipEmptySlotIndexes = new List <SlotIndex>();

            while (currentTime < endTime)
            //Main loop needs to go through all the times of the day -> Create a new row for each time of day
            {
                BookingRow row = new BookingRow();
                row.WeekDays = new List <WeeklyHeader>();
                row.Slots    = new List <BookingSlot>();
                row.Slots.Add(new BookingSlot {
                    RoomName = "Time", IsTime = true, StartTime = currentTime
                });

                int colIndex = 0;

                //Add Column Headers
                foreach (var day in weekDays)
                {
                    row.WeekDays.Add(new WeeklyHeader {
                        Weekday = day.Weekday, DayOfWeek = day.DayOfWeek
                    });
                }

                //Add Content for each column
                for (var currentDay = startOfWeek; currentDay <= endOfWeek; currentDay = currentDay.AddDays(1))
                {
                    //at 7.30 and finishes on* Monday*at 18.30 we can't use it *alone*.

                    var currentBooking = weeklyRoomBookings.FirstOrDefault(b =>
                                                                           b.StartTime == currentDay.Add(currentTime.TimeOfDay) &&
                                                                           b.Room.RoomName == roomName);

                    AddBookingSlots(currentBooking, row, skipEmptySlotIndexes, rowIndex, colIndex, currentTime, currentDay, roomName, false, null, null);
                    colIndex++;
                }

                bookingTable.Rows.Add(row);
                currentTime = currentTime.AddMinutes(30);
                rowIndex++;
            }

            return(bookingTable);
        }
Ejemplo n.º 2
0
        public void AddBookingSlots(Booking currentBooking, BookingRow row, List <SlotIndex> skipEmptySlotIndexes, int rowIndex, int colIndex, DateTime currentTime, DateTime currentDay, string roomName, bool isDaily, IEnumerable <Room> bookingRooms, Room room)
        {
            if (currentBooking != null)
            {
                var durationTimeSpan = currentBooking.EndTime - currentBooking.StartTime;
                var duration         = (int)durationTimeSpan.TotalMinutes / 30;

                row.Slots.Add(new BookingSlot {
                    BookingType = currentBooking.BookingType, BookingId = currentBooking.BookingId, RoomName = roomName, IsBooked = true, IsTime = false, Duration = duration, StartTime = currentBooking.StartTime, EndTime = currentBooking.EndTime, Title = currentBooking.Title
                });
                if (isDaily == true)
                {
                    row.Rooms.Add(new RoomHeader {
                        RoomName = room.RoomName, Capacity = room.Capacity
                    });
                }
                if (duration > 1)
                {
                    AddSkipLocations(skipEmptySlotIndexes, duration, rowIndex, colIndex);
                }
            }
            else if (skipEmptySlotIndexes.IsEmptySlotRequired(colIndex, rowIndex))
            {
                row.Slots.Add(new BookingSlot {
                    CurrentDay = currentDay.Date, RoomName = roomName, IsBooked = false, IsTime = false, Duration = 1, StartTime = currentTime, EndTime = currentTime.AddMinutes(30)
                });
                if (isDaily == true)
                {
                    row.Rooms.Add(new RoomHeader {
                        RoomName = room.RoomName, Capacity = room.Capacity
                    });
                }
            }
        }
Ejemplo n.º 3
0
        //creates table for daily bookings.
        public BookingTable GetDailyBookings(DateTime date)
        {
            IEnumerable <Room> bookingRooms = bookingRepository.GetBookingRooms();
            BookingTable       bookingTable = new BookingTable();

            bookingTable.Rows = new List <BookingRow>();

            bookingTable.Today = date;

            DateTime currentTime = date.Date.AddHours(7);
            DateTime endTime     = date.Date.AddHours(19);

            int rowIndex             = 0;
            var skipEmptySlotIndexes = new List <SlotIndex>();

            while (currentTime < endTime)
            {
                BookingRow row = new BookingRow();
                row.Slots = new List <BookingSlot>();
                row.Rooms = new List <RoomHeader>();
                row.Slots.Add(new BookingSlot {
                    RoomName = "Time", IsTime = true, StartTime = currentTime
                });

                int colIndex = 0;

                foreach (var room in bookingRooms)
                {
                    IEnumerable <Booking> bookingsByDate = bookingRepository.GetBookingByDate(date).Where(r => r.Room.RoomName.Equals(room.RoomName));

                    Booking currentBooking = bookingsByDate.FirstOrDefault(b => b.StartTime.Equals(currentTime));

                    AddBookingSlots(currentBooking, row, skipEmptySlotIndexes, rowIndex, colIndex, currentTime, date.Date, room.RoomName, true, bookingRooms, room);
                    colIndex++;
                }
                bookingTable.Rows.Add(row);

                currentTime = currentTime.AddMinutes(30);
                rowIndex++;
            }
            return(bookingTable);
        }