Esempio n. 1
0
 public BookingId Create(TenantId tenantId, CustomerId customerId, TherapyId therapyId, DateTimeOffset proposedTime, TimeSpan duration)
 {
     using (var uow = _unitOfWorkFactory.CreateSession())
     {
         // Create booking, add to repo and commit
         var booking = _bookingFactory.Create(tenantId, customerId, therapyId, proposedTime, duration);
         uow.GetRepository <IBookingWriteRepository>().Add(booking);
         uow.Commit();
         return(booking.BookingId);
     }
 }
        public void Handle(string flightNumber, int customerId, int passengerId)
        {
            var flight = _flightRepository.GetAll().SingleOrDefault(x => x.Number == flightNumber);

            if (flight == null)
            {
                throw new ValidationException("Flight does not exist");
            }

            var customer = _personRepository.Get(customerId);

            if (customer == null)
            {
                throw new ValidationException("Customer does not exist");
            }

            var passenger = _personRepository.Get(passengerId);

            if (passenger == null)
            {
                throw new ValidationException("Passenger does not exist");
            }

            var existingPassengerBooking = FindBooking(flightNumber, passengerId);

            if (existingPassengerBooking != null)
            {
                throw new ValidationException("The Passenger is already registered for the flight");
            }

            var newBooking = _bookingFactory.Create();

            newBooking.Customer   = customer;
            newBooking.Flight     = flight;
            newBooking.Passengers = new[] { passenger };
            _bookingRepository.Save(newBooking);
        }