Ejemplo n.º 1
0
        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();
            }));
        }
Ejemplo n.º 2
0
        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();
            }));
        }
        protected override IMessage Process(GetAvailableCarsQuery command)
        {
            var allCars      = repository.GetAll();
            var rentedCars   = rentalRepository.GetCurrentlyRentedCars().ToList();
            var reservedCars = reservationRepository.GetAll().ToList();

            var availableCars = allCars.Where(car =>
                                              carRentalEngine.IsCarAvailableForRental(car.CarId, command.PickupDate, command.ReturnDate, rentedCars, reservedCars));

            return(new GetCarsResponse {
                Cars = availableCars.ToArray()
            });
        }