Beispiel #1
0
        public Dictionary <CarModel, decimal> FindAvailableCarsForRental(CustomerModel customer, DateTime requestedReservationStartDateTime, DateTime requestedReservationEndDateTime, string city)
        {
            var     r             = new ReservationService();
            var     availableCars = r.FindAvailableCars(requestedReservationStartDateTime, requestedReservationEndDateTime, city);
            decimal cp            = 0;
            var     result        = new Dictionary <CarModel, decimal>();

            #region Calculate price

            foreach (var availableCar in availableCars)
            {
                switch (availableCar.Category)
                {
                case "A":
                {
                    cp = 50 * (requestedReservationEndDateTime - requestedReservationStartDateTime).Days;

                    switch (customer.CustomerType)
                    {
                    case CustomerModel.ConsumerPremium:
                    {
                        cp = cp - (cp * 0.02m);
                        break;
                    }
                    }

                    break;
                }

                case "B":
                {
                    cp = 65 * (requestedReservationEndDateTime - requestedReservationStartDateTime).Days;

                    switch (customer.CustomerType)
                    {
                    case CustomerModel.ConsumerPremium:
                    {
                        cp = cp - (cp * 0.03m);
                        break;
                    }

                    case CustomerModel.BusinessPremium:
                    {
                        cp = cp - (cp * 0.04m);
                        break;
                    }
                    }

                    break;
                }

                case "C":
                {
                    cp = 90 * (requestedReservationEndDateTime - requestedReservationStartDateTime).Days;

                    switch (customer.CustomerType)
                    {
                    case CustomerModel.ConsumerPremium:
                    {
                        cp = cp - (cp * 0.05m);
                        break;
                    }

                    case CustomerModel.Business:
                    {
                        cp = cp - (cp * 0.06m);
                        break;
                    }

                    case CustomerModel.BusinessPremium:
                    {
                        cp = cp - (cp * 0.08m);
                        break;
                    }
                    }

                    break;
                }

                case "D":
                {
                    cp = 120 * (requestedReservationEndDateTime - requestedReservationStartDateTime).Days;

                    switch (customer.CustomerType)
                    {
                    case CustomerModel.ConsumerPremium:
                    {
                        cp = cp - (cp * 0.06m);
                        break;
                    }

                    case CustomerModel.Business:
                    {
                        cp = cp - (cp * 0.08m);
                        break;
                    }

                    case CustomerModel.BusinessPremium:
                    {
                        cp = cp - (cp * 0.12m);
                        break;
                    }
                    }

                    break;
                }

                default:
                {
                    cp = 0;
                    break;
                }
                }

                result.Add(availableCar, cp);
            }
            #endregion

            return(result.Count > 0  ? result : null);
        }