예제 #1
0
        public virtual int SaveChanges(List <Booking> bookings, bool dontCheckClash)
        {
            int objectsWritten = 0;

            if (!dontCheckClash)
            {
                AvailabilityService aC = new AvailabilityService(_bookingRepository, _roomRepository, _locationRepository);
                List <Booking>      clashedBookings;

                using (var scope = TransactionUtils.CreateTransactionScope())
                {
                    foreach (var b in bookings)
                    {
                        bool invalid = aC.DoesMeetingClash(b, out clashedBookings);
                        //Checks if the booking that clashed is the current booking being saved, this allows us to edit bookings.
                        if (clashedBookings.Count == 1)
                        {
                            if (invalid && b.ID != 0)
                            {
                                invalid = !(b.ID == clashedBookings[0].ID);
                            }
                        }

                        if (invalid)
                        {
                            throw new BookingConflictException("Simultaneous booking conflict, please try again.");
                        }
                    }

                    //We dont mess around with the recurrence ID's after they are first created. So if the first booking in the batch has an ID, it exists in the DB. So dont go on further.
                    if (bookings.First().ID == 0)
                    {
                        int?recurrenceId = bookings.Select(x => x.RecurrenceId).FirstOrDefault();
                        //Check if the recurrence id is infact the next id in the DB (could potentially not be if a recurrence was made during execution of this request)
                        int nextRecurrenceId = _bookingRepository.GetNextRecurrenceId();
                        if (recurrenceId != null && recurrenceId != nextRecurrenceId)
                        {
                            //if the bookings recurrenceid is not the next, then set it.
                            bookings.ForEach(x => x.RecurrenceId = nextRecurrenceId);
                        }
                    }
                    objectsWritten = base.SaveChanges();
                    scope.Complete();
                }
            }
            else
            {
                objectsWritten = base.SaveChanges();
            }
            return(objectsWritten);
        }
예제 #2
0
        public virtual int SaveChanges(Booking booking, bool dontCheckClash)
        {
            List <Booking> clashedBookings;
            int            objectsWritten = 0;

            if (!dontCheckClash)
            {
                using (var scope = TransactionUtils.CreateTransactionScope())
                {
                    AvailabilityService aC = new AvailabilityService(_bookingRepository, _roomRepository, _locationRepository);

                    bool invalid = aC.DoesMeetingClash(booking, out clashedBookings);
                    //Checks if the booking that clashed is the current booking being saved, this allows us to edit bookings.
                    if (clashedBookings.Count == 1)
                    {
                        if (invalid && booking.ID != 0)
                        {
                            invalid = !(booking.ID == clashedBookings[0].ID);
                        }
                    }

                    if (invalid)
                    {
                        throw new BookingConflictException("Simultaneous booking conflict, please try again.");
                    }

                    objectsWritten = base.SaveChanges();
                    scope.Complete();
                }
            }
            else
            {
                objectsWritten = base.SaveChanges();
            }
            return(objectsWritten);
        }
예제 #3
0
        public List <RoomDTO> GetAvailableRoomsForLocation(string location, DateTime start, DateTime end, int numberOfPeople, bool smartRoom, int existingBookignId)
        {
            List <RoomDTO> rooms = new List <RoomDTO>();

            if (location == null)
            {
                return(new List <RoomDTO>());
            }

            List <Room> roomData = new List <Room>();

            //var locationRooms = db.Rooms.Where(x => x.Location.Name == location && x.SeatCount >= numberOfPeople).ToList();

            try
            {
                List <Room> availableRooms = new List <Room>();

                Booking existingBooking = _bookingRepository.GetById(existingBookignId);

                List <Booking> clashedBookings;
                existingBooking.StartDate = start;
                existingBooking.EndDate   = end;

                AvailabilityService availabilityService = new AvailabilityService(_bookingRepository, _roomsRepository, _locationRepository);
                bool meetingClash = availabilityService.DoesMeetingClash(existingBooking, out clashedBookings);

                if (meetingClash && clashedBookings.Count == 1 && clashedBookings[0].ID == existingBooking.ID)
                {
                    availableRooms.Add(existingBooking.Room);
                }

                else
                {
                    availableRooms = db.Rooms.Where(x => x.Location.Name == location && x.SeatCount >= numberOfPeople && x.Active == true && x.SmartRoom == smartRoom &&
                                                    (x.Bookings.Where(b => start <b.EndDate && end> b.StartDate && b.ID != existingBookignId).Count() == 0)) //Do any bookings overlap
                                     .OrderBy(r => r.SeatCount)
                                     .ToList();
                }
                roomData.AddRange(availableRooms);

                roomData.ForEach(x => rooms.Add(new RoomDTO()
                {
                    ID            = x.ID,
                    RoomName      = x.RoomName,
                    PhoneCount    = x.PhoneCount,
                    ComputerCount = x.ComputerCount,
                    SeatCount     = x.SeatCount,
                    SmartRoom     = x.SmartRoom,
                    Bookings      = x.Bookings.Where(b => b.StartDate.Date == start.Date && b.EndDate.Date == end.Date).Select(b =>
                    {
                        BookingDTO bDto = new BookingDTO()
                        {
                            ID             = b.ID,
                            Owner          = b.Owner,
                            StartDate      = b.StartDate,
                            EndDate        = b.EndDate,
                            IsSmartMeeting = b.IsSmartMeeting
                        };
                        return(bDto);
                    }).ToList()
                }));
            }
            catch (Exception ex)
            {
                _logger.ErrorException("Unable to get available rooms for location: " + location, ex);
            }
            return(rooms);
        }
예제 #4
0
        public List <Booking> GetAvailableSmartRoomBookings(Booking newBooking, out List <Booking> clashedBookings)
        {
            List <Booking> bookingsToCreate = new List <Booking>();
            List <Booking> clashedBs        = new List <Booking>();
            List <int>     smartRoomIds     = new List <int>();

            smartRoomIds.Add(newBooking.RoomID);

            AvailabilityService aC = new AvailabilityService(this, _roomRepository, _locationRepository);

            foreach (var smartLoc in newBooking.SmartLoactions)
            {
                int smartLocId = 0;
                int.TryParse(smartLoc, out smartLocId);

                Room smartLocData = db.Rooms.Where(x => x.ID == smartLocId).Select(x => x).ToList().FirstOrDefault();

                List <Booking> doesClash;
                Room           roomToBook = null;
                if (aC.DoesMeetingClash(new Booking()
                {
                    StartDate = newBooking.StartDate, EndDate = newBooking.EndDate, RoomID = smartLocData.ID
                }, out doesClash))
                {
                    roomToBook = aC.GetAlternateSmartRoom(smartRoomIds, newBooking.StartDate, newBooking.EndDate, db.Locations.Single(l => l.Name == smartLocData.Location.Name).ID);
                }
                else
                {
                    roomToBook = smartLocData;
                }

                if (roomToBook == null || bookingsToCreate.Select(x => x.Room).Contains(roomToBook))
                {
                    clashedBs.Add(new Booking()
                    {
                        StartDate      = newBooking.StartDate,
                        Owner          = newBooking.Owner,
                        IsSmartMeeting = true,
                        Room           = smartLocData
                    });
                }
                else
                {
                    bookingsToCreate.Add(new Booking()
                    {
                        DssAssist         = newBooking.DssAssist,
                        ExternalAttendees = newBooking.ExternalAttendees,
                        Flipchart         = newBooking.Flipchart,
                        NumberOfAttendees = newBooking.Room.SeatCount,
                        Owner             = newBooking.Owner,
                        PID            = newBooking.PID,
                        Projector      = newBooking.Projector,
                        RoomID         = roomToBook.ID,
                        Room           = roomToBook,
                        Subject        = newBooking.Subject,
                        StartDate      = newBooking.StartDate,
                        EndDate        = newBooking.EndDate,
                        IsSmartMeeting = true
                    });

                    smartRoomIds.Add(roomToBook.ID);
                }
            }

            clashedBookings = clashedBs;

            _logger.Trace(LoggerHelper.ExecutedFunctionMessage(bookingsToCreate, clashedBookings));

            return(bookingsToCreate);
        }