예제 #1
0
        public virtual RoomBookingDTO Compute(Client currentClient, int id, object param)
        {
            repo = (IRoomBookingRepository)base.repo;
            List <PeopleBooking> listPeopleBooking = null;
            List <Period>        listPeriod        = null;

            repo.includes.Add("Booking");
            repo.includes.Add("Room");
            ProcessDTOPostPut(null, id, currentClient);
            ValidateOrig();
            repo.includes.Add("PeopleCategory");
            listPeopleBooking = repo.GetPeopleBookingFromRoomBooking(orig.Id, currentClient.Id).ToList();
            listPeriod        = repo.GetPeriods((DateTime)orig.Booking.DateArrival, (DateTime)orig.Booking.DateDeparture, currentClient.Id).ToList();

            finalPriceHT  = 0;
            finalPriceTTC = 0;
            if (listPeopleBooking.Count == 0)
            {
                ComputeUniqPrice(listPeriod, currentClient);
            }
            else
            {
                ComputePricePerPerson(listPeopleBooking, listPeriod, currentClient);
            }
            if (!validationDictionnary.IsValid)
            {
                throw new ManahostValidationException(validationDictionnary);
            }
            orig.PriceHT  = finalPriceHT;
            orig.PriceTTC = finalPriceTTC;
            repo.Update(orig);
            repo.Save();
            return(GetMapper.Map <RoomBooking, RoomBookingDTO>(orig));
        }
예제 #2
0
        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));
        }
예제 #3
0
 protected override void DoPostAfterSave(Client currentClient, RoomBooking entity, object param)
 {
     if (entity.DateBegin == null || entity.DateEnd == null)
     {
         if (entity.DateBegin == null)
         {
             entity.DateBegin = entity.Booking.DateArrival;
         }
         if (entity.DateEnd == null)
         {
             entity.DateEnd = entity.Booking.DateDeparture;
         }
         ComputeNbNights(entity);
         repo.Update(entity);
         repo.Save();
     }
 }