예제 #1
0
        public Rental RentCarToCustomer(string loginEmail, int carId, DateTime rentalDate, DateTime dateDueBack)
        {
            return(ExecuteFaultHandledOperation(() =>
            {
                ICarRentalEngine carRentalEngine = _BusinessEngineFactory.GetBusinessEngine <ICarRentalEngine>();

                try
                {
                    Rental rental = carRentalEngine.RentCarToCustomer(loginEmail, carId, rentalDate, dateDueBack);

                    return rental;
                }
                catch (UnableToRentForDateException ex)
                {
                    throw new FaultException <UnableToRentForDateException>(ex, ex.Message);
                }
                catch (CarCurrentlyRentedException ex)
                {
                    throw new FaultException <CarCurrentlyRentedException>(ex, ex.Message);
                }
                catch (NotFoundException ex)
                {
                    throw new FaultException <NotFoundException>(ex, ex.Message);
                }
            }));
        }
        protected override IMessage Process(RentCarToCustomerCommand command)
        {
            var rental = carRentalEngine.RentCarToCustomer(command.LoginEmail, command.CarId,
                                                           command.RentalDate ?? DateTime.Now, command.DateDueBack);

            return(new GetRentalResponse {
                Rental = rental
            });
        }
예제 #3
0
 public Rental RentCarToCustomer(string loginEmail, int carid, DateTime rentalDate, DateTime dueDate)
 {
     return(HandleFaultHandledOperation(() =>
     {
         ICarRentalEngine rentalEngine = _BusinessEngineFactory.GetBusinessEngineFactory <ICarRentalEngine>();
         IAccountRepository accountRepository = _DataRepositoryFactory.GetDataRepository <IAccountRepository>();
         Account account = accountRepository.GetByLogin(loginEmail);
         if (account == null)
         {
             NotFoundException exception = new NotFoundException(string.Format("Account not found for login {0}", loginEmail));
             throw new FaultException <NotFoundException>(exception, exception.Message);
         }
         Rental rental = rentalEngine.RentCarToCustomer(loginEmail, account.AccountId, carid, rentalDate, dueDate);
         return rental;
     }));
 }
예제 #4
0
        public void ExecuteRentalFromReservation(int reservationId)
        {
            ExecuteFaultHandledOperation(() =>
            {
                IAccountRepository accountRepository         = _dataRepositoryFactory.GetDataRepository <IAccountRepository>();
                IReservationRepository reservationRepository = _dataRepositoryFactory.GetDataRepository <IReservationRepository>();
                ICarRentalEngine carRentalEngine             = _businessEngineFactory.GetBusinessEngine <ICarRentalEngine>();

                Reservation reservation = reservationRepository.Get(reservationId);
                if (reservation == null)
                {
                    NotFoundException ex = new NotFoundException(string.Format("Reservation {0} is not found.", reservationId));
                    throw new FaultException <NotFoundException>(ex, ex.Message);
                }

                Account account = accountRepository.Get(reservation.AccountId);
                if (account == null)
                {
                    NotFoundException ex = new NotFoundException(string.Format("No account found for account ID '{0}'.", reservation.AccountId));
                    throw new FaultException <NotFoundException>(ex, ex.Message);
                }

                try
                {
                    //Call to business engine
                    Rental rental = carRentalEngine.RentCarToCustomer(account.LoginEmail, reservation.CarId, reservation.RentalDate, reservation.ReturnDate);
                }
                catch (UnableToRentForDateException ex)
                {
                    throw new FaultException <UnableToRentForDateException>(ex, ex.Message);
                }
                catch (CarCurrentlyRentedException ex)
                {
                    throw new FaultException <CarCurrentlyRentedException>(ex, ex.Message);
                }
                catch (NotFoundException ex)
                {
                    throw new FaultException <NotFoundException>(ex, ex.Message);
                }

                reservationRepository.Remove(reservation);
            });
        }
예제 #5
0
        public void ExecuteRentalFromReservation(int reservationId)
        {
            HandleFaultHandledOperation(() =>
            {
                IReservationRepository reservationRepository = _DataRepositoryFactory.GetDataRepository <IReservationRepository>();
                IAccountRepository accountRepository         = _DataRepositoryFactory.GetDataRepository <IAccountRepository>();
                ICarRentalEngine rentalEngine = _BusinessEngineFactory.GetBusinessEngineFactory <ICarRentalEngine>();

                Reservation reservation = reservationRepository.Get(reservationId);
                if (reservation == null)
                {
                    NotFoundException exception = new NotFoundException(string.Format("Reservation not found for {0}", reservationId));
                    throw new FaultException <NotFoundException>(exception, exception.Message);
                }

                Account account = accountRepository.Get(reservation.AccountId);
                if (account == null)
                {
                    NotFoundException exception = new NotFoundException(string.Format("Account not found for {0}", reservation.AccountId));
                    throw new FaultException <NotFoundException>(exception, exception.Message);
                }

                try
                {
                    Rental rental = rentalEngine.RentCarToCustomer(account.LoginEmail, account.AccountId, reservation.CarId, reservation.RentalDate, reservation.ReturnDate);
                }
                catch (UnableToRentForDateException ex)
                {
                    throw new FaultException <UnableToRentForDateException>(ex, ex.Message);
                }
                catch (NotFoundException ex)
                {
                    throw new FaultException <NotFoundException>(ex, ex.Message);
                }
            });
        }
예제 #6
0
        protected override IMessage Process(ExecuteRentalFromReservationCommand command)
        {
            var reservation = repository.Get(command.ReservationId);

            if (reservation == null)
            {
                throw new NotFoundException(string.Format("Reservation {0} is not found.", command.ReservationId));
            }

            var account = accountRepository.Get(reservation.AccountId);

            if (account == null)
            {
                throw new NotFoundException(string.Format("No account found for account ID '{0}'.", reservation.AccountId));
            }

            carRentalEngine.RentCarToCustomer(account.LoginEmail, reservation.CarId, reservation.RentalDate, reservation.ReturnDate);

            repository.Remove(reservation);

            return(new StatusResponse {
                Status = true
            });
        }