public Car[] GetAvailableCars(DateTime pickupDate, DateTime returnDate) { return(ExecuteFaultHandledOperation(() => { ICarRepository carRepository = _DataRepositoryFactory.GetDataRepository <ICarRepository>(); IRentalRepository rentalRepository = _DataRepositoryFactory.GetDataRepository <IRentalRepository>(); IReservationRepository reservationRepository = _DataRepositoryFactory.GetDataRepository <IReservationRepository>(); ICarRentalEngine carRentalEngine = _BusinessEngineFactory.GetBusinessEngine <ICarRentalEngine>(); IEnumerable <Car> allCars = carRepository.Get(); IEnumerable <Rental> rentedCars = rentalRepository.GetCurrentlyRentedCars(); IEnumerable <Reservation> reservedCars = reservationRepository.Get(); List <Car> availableCars = new List <Car>(); foreach (Car car in allCars) { if (carRentalEngine.IsCarAvailableForRental(car.CarId, pickupDate, returnDate, rentedCars, reservedCars)) { availableCars.Add(car); } } return availableCars.ToArray(); })); }
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); } })); }
public bool IsCarCurrentlyRented(int carId) { return(ExecuteFaultHandledOperation(() => { ICarRentalEngine carRentalEngine = _BusinessEngineFactory.GetBusinessEngine <ICarRentalEngine>(); return carRentalEngine.IsCarCurrentlyRented(carId); })); }
public Car[] GetAllAvailableCars(DateTime pickUpDate, DateTime returnDate) { string userName = Thread.CurrentPrincipal.Identity.Name; return(ExecuteFaultHandledOperation(() => { ICarRepository carRepository = _DataRepositoryFactory.GetDataRepository <ICarRepository>(); IRentalRepository rentalRepository = _DataRepositoryFactory.GetDataRepository <IRentalRepository>(); IReservationRepository reservationRepository = _DataRepositoryFactory.GetDataRepository <IReservationRepository>(); ICarRentalEngine engine = _BusinessEngineFactory.GetBusinessEngine <ICarRentalEngine>(); IEnumerable <Car> allCars = carRepository.Get(); IEnumerable <Rental> rentedCars = rentalRepository.GetCurrentlyRentedCars(); IEnumerable <Reservation> reservedCars = reservationRepository.Get(); List <Car> availablesCars = new List <Car>(); foreach (var car in allCars) { if (engine.IsCarAvailableForRental(car.CarId, pickUpDate, returnDate, rentedCars, reservedCars)) { availablesCars.Add(car); } } return new List <Car>().ToArray(); })); }
/// <summary> /// Initializes a new instance of the MessageHandlerBase class. /// </summary> public GetAvailableCarsHandler(ICarRepository repository, IRentalRepository rentalRepository, IReservationRepository reservationRepository, ICarRentalEngine carRentalEngine) : base(repository) { this.rentalRepository = rentalRepository; this.reservationRepository = reservationRepository; this.carRentalEngine = carRentalEngine; }
public void GetAvailableCars() { // FactoryRepositoryTestClass repository = new FactoryRepositoryTestClass(); IDataRepositoryFactory fact = new DataRepositoryFactory(); ICarRepository car = fact.GetDataRepository <ICarRepository>(); IBusinessEngineFactory engine = new BusinessEngineFactory(); ICarRentalEngine carEngine = engine.GetBusinessEngineFactory <ICarRentalEngine>(); InventoryManager mgr = new InventoryManager(engine); Car[] cars = mgr.GetAvailableCar(new DateTime(2016, 01, 04), new DateTime(2016, 01, 07)); //IEnumerable<Car> result = repository.GetAvailableCars(); }
public void AcceptCarReturn(int carId) { ExecuteFaultHandledOperation(() => { IRentalRepository rentalRepository = _DataRepositoryFactory.GetDataRepository <IRentalRepository>(); ICarRentalEngine carRentalEngine = _BusinessEngineFactory.GetBusinessEngine <ICarRentalEngine>(); Rental rental = rentalRepository.GetRentalByCar(carId); if (rental == null) { CarNotRentedException ex = new CarNotRentedException($"Car id {carId} is not currently rented"); throw new FaultException <CarNotRentedException>(ex, ex.Message); } rental.DateReturned = DateTime.Now; Rental updatedRentalEntity = rentalRepository.Update(rental); }); }
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; })); }
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); }); }
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; })); }
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); } }); }
/// <summary> /// Initializes a new instance of the MessageHandlerBase class. /// </summary> public IsCarCurrentlyRentedHandler(IRentalRepository repository, ICarRentalEngine carRentalEngine) : base(repository) { this.carRentalEngine = carRentalEngine; }
/// <summary> /// Initializes a new instance of the MessageHandlerBase class. /// </summary> public RentCarToCustomerHandler(IRentalRepository repository, ICarRentalEngine carRentalEngine) : base(repository) { this.carRentalEngine = carRentalEngine; }
/// <summary> /// Initializes a new instance of the MessageHandlerBase class. /// </summary> public ExecuteRentalFromReservationHandler(IReservationRepository repository, IAccountRepository accountRepository, ICarRentalEngine carRentalEngine) : base(repository) { this.accountRepository = accountRepository; this.carRentalEngine = carRentalEngine; }