Esempio n. 1
0
 public bool IsCarCurrentlyRented(int carId)
 {
     return(ExecuteFaultHandledOperation(() => {
         ICarRentalEngine carRentalEngine = _BusinessEngineFactory.GetBusinessEngine <ICarRentalEngine>();
         return carRentalEngine.IsCarCurrentlyRented(carId);
     }));
 }
Esempio n. 2
0
        public Rental RentCarToCustomer(string loginEmail, int carId, DateTime rentalDate, DateTime dateDueBack)
        {
            return(ExecuteFaultHandledOperation(() =>
            {
                if (rentalDate > DateTime.Now)
                {
                    UnableToRentForDateException ex = new UnableToRentForDateException(string.Format("Cannot rent for date {0} yet.", rentalDate.ToShortDateString()));
                    throw new FaultException <UnableToRentForDateException>(ex, ex.Message);
                }

                IAccountRepository accountRepository = _DataRepositoryFactory.GetDataRepository <IAccountRepository>();
                IRentalRepository rentalRepository = _DataRepositoryFactory.GetDataRepository <IRentalRepository>();
                ICarRentalEngine carRentalEngine = _BusinessEngineFactory.GetBusinessEngine <ICarRentalEngine>();

                bool carIsRented = carRentalEngine.IsCarCurrentlyRented(carId);
                if (carIsRented)
                {
                    CarCurrentlyRentedException ex = new CarCurrentlyRentedException(string.Format("Car {0} is already rented.", carId));
                    throw new FaultException <CarCurrentlyRentedException>(ex, ex.Message);
                }

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

                Rental rental = new Rental()
                {
                    AccountId = account.AccountId,
                    CarId = carId,
                    DateRented = rentalDate,
                    DateDue = dateDueBack
                };

                Rental savedEntity = rentalRepository.Add(rental);

                return savedEntity;
            }));
        }
Esempio n. 3
0
 protected override IMessage Process(IsCarCurrentlyRentedQuery command)
 {
     return(new StatusResponse {
         Status = carRentalEngine.IsCarCurrentlyRented(command.CarId)
     });
 }