Beispiel #1
0
        public long Execute()
        {
            if (Input.Start.Day != Input.End.Date.Day || Input.Start.Date < DateTime.Today)
            {
                return(-1);
            }
            var placeId  = roomRepository.GetById(Input.RoomId).PlaceId;
            var openings = timeSlotRepository.GetAllOfPlace(placeId)
                           .Find(op => op.Day == Input.Start.DayOfWeek);

            if (openings == null)
            {
                return(-1);
            }
            if (Input.Start.Hour < openings.StartHour || new TimeSpan(0, Input.End.Hour, Input.End.Minute, 0)
                > new TimeSpan(0, openings.EndHour, openings.EndMinutes, 0))
            {
                throw new Exception("Erreur: Impossible de réserver une salle hors des heures d'ouvertures");
            }
            var date       = new DateTime(Input.Start.Year, Input.Start.Month, Input.Start.Day);
            var otherSlots = roomBookingRepository.GetAllFromGivenDate(date);

            if (otherSlots != null)
            {
                var noOverlap = otherSlots.Where(slot => Input.RoomId == slot.RoomId || slot.ClientId == Input.ClientId)
                                .All((slot => slot.End <= Input.Start || slot.Start >= Input.End));
                if (!noOverlap)
                {
                    return(-1);
                }
            }
            var roomBooking = new domain.RoomBooking(Input.Start, Input.End, Input.RoomId, Input.ClientId);

            return(roomBookingRepository.Create(roomBooking));
        }
        public long Execute()
        {
            if (roomBooking.Start.Day != roomBooking.End.Date.Day || roomBooking.Start.Date < DateTime.Today)
            {
                return(-1);
            }
            var placeId  = roomRepository.GetById(roomBooking.RoomId).PlaceId;
            var openings = timeSlotRepository.GetAllOfPlace(placeId)
                           .Find(op => op.Day == roomBooking.Start.DayOfWeek);

            if (openings == null)
            {
                return(-1);
            }
            if (roomBooking.Start.Hour < openings.StartHour || new TimeSpan(0, roomBooking.End.Hour, roomBooking.End.Minute, 0)
                > new TimeSpan(0, openings.EndHour, openings.EndMinutes, 0))
            {
                throw new Exception("Erreur: Impossible de réserver du matériel hors des heures d'ouvertures");
            }
            var date = new DateTime(roomBooking.Start.Year, roomBooking.Start.Month, roomBooking.Start.Day);
            var possibleConflicts = roomBookingRepository.GetAllFromGivenDate(date);
            var hasNoConflict     = possibleConflicts.Where(rb => rb.Id != roomBooking.Id).ToList().All(booking =>
                                                                                                        booking.End <= roomBooking.Start || booking.Start >= roomBooking.End);

            if (!hasNoConflict)
            {
                throw new Exception("Une réservation est déjà présente pour ces horaires");
            }
            return(roomBookingRepository.Update(roomBooking));
        }
Beispiel #3
0
 public IEnumerable <domain.RoomBooking> Execute()
 {
     return(roomBookingRepository.GetAllFromGivenDate(DateTime));
 }