public void SendCarOnRent(CarFacade carFacade, Client client, RentTime time)
        {
            CheckCarCanGoOnRent(carFacade, time);

            AddRentHistoryToClient(client, carFacade, time);
            AddRentHistoryToCar(carFacade, time);
        }
        private void AddServiceHistoryToCar(CarFacade carFacade, DateTimeOffset startTime)
        {
            var endTimeOfService = startTime.AddDays(7);
            var serviceTime      = new RentTime(startTime, endTimeOfService);

            carFacade.Car.Services.Add(serviceTime);
            carFacade.Car.SetCountToServiceToZero();
            CarRepository.Update(carFacade.Car);
        }
Ejemplo n.º 3
0
 public void RentCar(CarFacade carFacade, RentTime time)
 {
     if (HasCarAt(time))
     {
         throw new Exception("У клиента " + Name + " уже есть машина в аренде во это время: " + time);
     }
     else
     {
         RentHistory.Add(time, carFacade);
     }
 }
Ejemplo n.º 4
0
        public bool IsCrossedWith(RentTime time)
        {
            var isCrossed = true;

            if (((StartTime > time.EndTime) && (EndTime > time.EndTime)) ||
                ((StartTime < time.StartTime) && (EndTime < time.EndTime)))
            {
                isCrossed = false;
            }

            return(isCrossed);
        }
        public List <Car> GetCarsAt(RentTime time)
        {
            var cars = new List <Car>();

            foreach (var car in CarRepository.GetList())
            {
                if (car.IsFreeAt(time))
                {
                    cars.Add(car);
                }
            }

            return(cars);
        }
Ejemplo n.º 6
0
        public bool IsAtServiceAt(RentTime time)
        {
            bool isAtService = false;

            foreach (var service in Services)
            {
                if (time.IsCrossedWith(service))
                {
                    isAtService = true;
                }
            }

            return(isAtService);
        }
Ejemplo n.º 7
0
        public bool IsAtRentAt(RentTime time)
        {
            bool isAtRent = false;

            foreach (var rent in Rents)
            {
                if (time.IsCrossedWith(rent))
                {
                    isAtRent = true;
                }
            }

            return(isAtRent);
        }
Ejemplo n.º 8
0
        public bool HasCarAt(RentTime time)
        {
            bool hasCar = false;

            foreach (var rent in RentHistory)
            {
                if (time.IsCrossedWith(rent.Key))
                {
                    hasCar = true;
                }
            }

            return(hasCar);
        }
        public void SendCarOnService(CarFacade carFacade, DateTimeOffset startTime)
        {
            var endTime = startTime.AddDays(7);
            var time    = new RentTime(startTime, endTime);

            if (carFacade.IsFreeAt(time))
            {
                AddServiceHistoryToCar(carFacade, startTime);
            }
            else
            {
                throw new Exception("Машина " + carFacade.Car.Name + " не может быть отправлена на тех обслуживание в "
                                    + startTime + ", так как занята");
            }
        }
        private void CheckCarCanGoOnRent(CarFacade carFacade, RentTime time)
        {
            if (carFacade.Car.CountToService >= 10)
            {
                throw new Exception("Машину " + carFacade.Car.Name + " нужно отправить на тех осмотр");
            }

            if (carFacade.Car.Rents.Count != 0 &&
                carFacade.Car.Rents.Last().EndTime > time.StartTime)
            {
                throw new Exception("Нельзя отправлять машину " + carFacade.Car.Name +
                                    " в аренду до уже существующей c " + time.StartTime + " до " + time.EndTime);
            }

            if (!carFacade.IsFreeAt(time))
            {
                throw new Exception("Машина " + carFacade.Car.Name + " занята в промежутке от "
                                    + time.StartTime + " до " + time.EndTime);
            }
        }
 public List <Car> GetCarsAt(RentTime time)
 {
     return(CarRentCompany.GetCarsAt(time));
 }
Ejemplo n.º 12
0
 public bool HasCarAt(RentTime time)
 {
     return(Client.HasCarAt(time));
 }
Ejemplo n.º 13
0
 public void RentCar(CarFacade carFacade, RentTime time)
 {
     Client.RentCar(carFacade, time);
 }
Ejemplo n.º 14
0
 public bool IsFreeAt(RentTime time)
 {
     return(!(IsAtRentAt(time) || IsAtServiceAt(time)));
 }
 public void SendCarOnRent(CarFacade carFacade, Client client, RentTime time)
 {
     CarRentCompany.SendCarOnRent(carFacade, client, time);
 }
 private void AddRentHistoryToClient(Client client, CarFacade carFacade, RentTime time)
 {
     client.RentCar(carFacade, time);
     ClientRepository.Update(client);
 }
Ejemplo n.º 17
0
 public bool IsFreeAt(RentTime time)
 {
     return(Car.IsFreeAt(time));
 }
Ejemplo n.º 18
0
 public bool IsAtRentAt(RentTime time)
 {
     return(Car.IsAtRentAt(time));
 }
Ejemplo n.º 19
0
 public bool IsAtServiceAt(RentTime time)
 {
     return(Car.IsAtServiceAt(time));
 }
 private void AddRentHistoryToCar(CarFacade carFacade, RentTime time)
 {
     carFacade.Car.IncreaseCountToService();
     carFacade.Car.Rents.Add(time);
     CarRepository.Update(carFacade.Car);
 }