/// <summary>
        /// Sets the flag which indicates of the rezervation is cancelled.
        /// </summary>
        /// <param name="rezervationId"></param>
        /// <returns>True if the operation complete successfully</returns>
        public bool CancelRezervation(int rezervationId, decimal cancelationFeeRate)
        {
            var dbRezervation = this.GetRezervation(rezervationId);

            if (dbRezervation.IsReturned)
            {
                throw new InvalidOperationException("Car already returned.");
            }

            dbRezervation.IsCancelled = true;

            var cancelationFee = CarTypes.GetCarType((CarTypeEnum)dbRezervation.CarType).GetCancellationFee(cancelationFeeRate);

            // cancelation fee cannot be bigger than the rental fee.
            dbRezervation.CancellationFee    = cancelationFee > dbRezervation.RentaltFee ? dbRezervation.RentaltFee : cancelationFee;
            dbRezervation.CancelationFeeRate = cancelationFeeRate;

            // we set this to 0 since the car is not rented.
            dbRezervation.RentaltFee = 0.0m;
            dbRezervation.DepositFee = 0.0m;

            this.dbContext.SaveChanges();

            return(true);
        }
        /// <summary>
        /// Sets the flag which indicates of the car is return and set rental fee if needed to be calculated.
        /// </summary>
        /// <param name="rezervationId"></param>
        /// <returns>True if the operation complete successfully</returns>
        public bool ReturnCar(int rezervationId)
        {
            var dbRezervation = this.GetRezervation(rezervationId);

            if (!dbRezervation.IsPickedUp || dbRezervation.IsCancelled)
            {
                throw new InvalidOperationException("Car has not been picked up yet, or rezervation cancelled.");
            }

            dbRezervation.IsReturned = true;

            // in case the return date is more that the one intially specified then recalucate the rental fee.
            if (dbRezervation.ReturnDate < DateTime.Now)
            {
                dbRezervation.RentaltFee = CarTypes.GetCarType((CarTypeEnum)dbRezervation.CarType).GetRentalFee(dbRezervation.PickUpDate, DateTime.Now);
            }
            dbRezervation.RentaltFee         = dbRezervation.RentaltFee;
            dbRezervation.CancelationFeeRate = 0.0m;
            dbRezervation.CancellationFee    = 0.0m;
            this.dbContext.SaveChanges();

            return(true);
        }
        /// <summary>
        /// Creates a booking for the client account.
        /// </summary>
        /// <param name="parameters">Rezervation creation parameters. Hold information on the client account and the rezervation.</param>
        /// <returns></returns>
        public RezervationModel CreateBooking(RezervationCreationParameters parameters)
        {
            this.ValidateBookingParameters(parameters);

            //try to get a client account first
            var clientAccount = this.dbContext.ClientAccounts.SingleOrDefault(x => x.ClientId == parameters.ClientId)?.ToModel();

            if (clientAccount == null && parameters.ClientAccount != null)
            {
                clientAccount = this.clientAccountService.Add(parameters.ClientAccount);
            }
            else if (parameters.ClientAccount == null && clientAccount == null)
            {
                throw new NotFoundException("Client account not found.");
            }

            var dbRezervation = new Rezervation()
            {
                ClientId       = clientAccount.ClientId,
                CarPlateNumber = parameters.CarPlateNumber,
                PickUpDate     = parameters.PickUpDate,
                ReturnDate     = parameters.ReturnDate,
            };

            //get the car type
            var carType = CarTypes.GetCarType(parameters.CarType);

            dbRezervation.CarType    = (int)carType.Type;
            dbRezervation.RentaltFee = carType.GetRentalFee(parameters.PickUpDate, parameters.ReturnDate);
            dbRezervation.DepositFee = carType.GetDepositFee(dbRezervation.RentaltFee);

            this.dbContext.Rezervations.Add(dbRezervation);
            this.dbContext.SaveChanges();

            return(dbRezervation.ToModel(clientAccount));
        }