Пример #1
0
        public string GenerateStatement()
        {
            GeneralStatement statementBuilder = new GeneralStatement(Name);

            double totalAmount = 0;
            var    factory     = new PriceCodeCalculatorFactory();

            foreach (var rental in _rentals)
            {
                double    rentalSum  = 0;
                int       daysRented = rental.DaysRented;
                PriceCode priceCode  = rental.Car.PriceCode;
                var       calculator = factory.GetRentalSumCalculator(priceCode);

                rentalSum = calculator.GetRentalSum(daysRented, PricePerDay);

                int customerRenterPoints = renterPointsManager.GetCustomerRenterPoints(rental.Customer.Name, rental.Id);
                if (customerRenterPoints - renterPointsManager.CalculateRenterPoints(priceCode, daysRented) >= 5 && priceCode != PriceCode.Luxury)
                {
                    rentalSum = calculator.ApplyDiscount(rentalSum);
                }

                statementBuilder.AddRentalDetails(rental.Customer.Name, customerRenterPoints, priceCode, rental.Car.Model, rental.DaysRented, rentalSum);
                totalAmount += rentalSum;
            }
            statementBuilder.AddTotalAmmount(totalAmount);

            return(statementBuilder.GetStatement());
        }
Пример #2
0
 public static PriceCodeModel ToModel(this PriceCode aPriceCodeEntity)
 {
     return(new PriceCodeModel()
     {
         PriceCodeId = aPriceCodeEntity.PriceCodeId,
         LongCode = aPriceCodeEntity.LongCode,
         ShortCode = aPriceCodeEntity.ShortCode,
         Description = aPriceCodeEntity.Description
     });
 }
Пример #3
0
        //Metoda necesara pentru a se putea calcula corect suma ce trebuie platita pentru un rental
        public int CalculateRenterPoints(PriceCode priceCode, int daysRented)
        {
            int frequentRenterPoints = 1;

            if (priceCode == PriceCode.Premium && daysRented > 1)
            {
                frequentRenterPoints++;
            }

            return(frequentRenterPoints);
        }
Пример #4
0
 private static double GetMoviePriceAmount(PriceCode priceCode, int daysRented)
 {
     return(priceCode switch
     {
         PriceCode.Regular when daysRented > 2 => 2 + (daysRented - 2) * 1.5,
         PriceCode.Regular => 2,
         PriceCode.NewRelease => daysRented * 3,
         PriceCode.Childrens when daysRented > 3 => 1.5 + (daysRented - 3) * 1.5,
         PriceCode.Childrens => 1.5,
         _ => throw new ArgumentOutOfRangeException(nameof(priceCode),
                                                    $"given price code '{priceCode}' is invalid.")
     });
 private void EditPriceCode()
 {
     txt1.Text   = PriceCode.GetPriceCodeForNumber(1);
     txt2.Text   = PriceCode.GetPriceCodeForNumber(2);
     txt3.Text   = PriceCode.GetPriceCodeForNumber(3);
     txt4.Text   = PriceCode.GetPriceCodeForNumber(4);
     txt5.Text   = PriceCode.GetPriceCodeForNumber(5);
     txt6.Text   = PriceCode.GetPriceCodeForNumber(6);
     txt7.Text   = PriceCode.GetPriceCodeForNumber(7);
     txt8.Text   = PriceCode.GetPriceCodeForNumber(8);
     txt9.Text   = PriceCode.GetPriceCodeForNumber(9);
     txt0.Text   = PriceCode.GetPriceCodeForNumber(0);
     txtDot.Text = PriceCode.GetPriceCodeForNumber(".");
 }
        public RentalSumCalculator GetRentalSumCalculator(PriceCode priceCode)
        {
            switch (priceCode)
            {
            case PriceCode.Regular:
                return(new RegularCalculator());

            case PriceCode.Mini:
                return(new MiniCalculator());

            case PriceCode.Luxury:
                return(new LuxuryCalculator());

            default:
                return(new PremiumCalculator());
            }
        }
Пример #7
0
        private MovieType ChooseType(PriceCode priceCode)
        {
            switch (priceCode)
            {
            case PriceCode.CHILDRENS:
                return(new ChildrensMovieType());

            case PriceCode.NEW_RELEASE:
                return(new NewReleaseMovieType());

            case PriceCode.REGULAR:
                return(new RegularMovieType());

            default:
                throw new InvalidOperationException("Unknown pricecode");
            }
        }
Пример #8
0
        //Cand este adaugat un rental, se calculeaza punctele pentru acel customer
        //Punctele se tin pentru fiecare rental in parte
        //Pentru un rental facut, se vor aduna punctele obtinute la valoarea calculata la un rental anterior(este mereu valoarea cea mai mare din dictionar)
        public void UpdateRenterPoints(string customerName, int rentalId, PriceCode priceCode, int daysRented)
        {
            if (!_customerPoints.ContainsKey(customerName))
            {
                _customerPoints.Add(customerName, new Dictionary <int, int>()
                {
                    { rentalId, 0 }
                });
            }
            else
            {
                _customerPoints[customerName].Add(rentalId, GetPointsMax(customerName));
            }

            _customerPoints[customerName][rentalId]++;

            if (priceCode == PriceCode.Premium && daysRented > 1)
            {
                _customerPoints[customerName][rentalId]++;
            }
        }
Пример #9
0
 public Car(PriceCode priceCode, string model)
 {
     PriceCode = priceCode;
     Model     = model;
 }
Пример #10
0
 public Movie(String title, PriceCode priceCode)
 {
     this.title = title;
     type       = ChooseType(priceCode);
 }
Пример #11
0
 public void SetPriceCode(PriceCode arg)
 {
     _priceCode = arg;
 }
Пример #12
0
 public void AddRentalDetails(string customerName, int customerFrequentRenterPoints, PriceCode priceCode, string carModel, int daysRented, double rentalSum)
 {
     _statement.Append(customerName + "\t" + customerFrequentRenterPoints + "\t" + priceCode + "\t" + carModel + "\t" + daysRented + "d \t" + rentalSum + " EUR\n");
 }
Пример #13
0
 public void SetPriceCode(PriceCode arg)
 {
     priceCode = arg;
 }
Пример #14
0
 public Movie(string title, PriceCode priceCode)
 {
     this.title = title;
     this.priceCode = priceCode;
 }
Пример #15
0
 public void SwitchType(PriceCode newPriceCode)
 {
     type = ChooseType(newPriceCode);
 }
Пример #16
0
 public void AddCarCategoryDetails(PriceCode carCategory, double rentalSum)
 {
     _statement.Append(carCategory + "\t\t" + rentalSum + " EUR\n");
 }
Пример #17
0
 public Movie(String title, PriceCode priceCode)
 {
     this.title     = title;
     this.pricecode = priceCode;
 }
Пример #18
0
 public Movie(string title, PriceCode priceCode)
 {
     Title     = title;
     PriceCode = priceCode;
 }
Пример #19
0
 public Movie(string title, PriceCode priceCode)
 {
     this.Title     = title;
     this.PriceCode = priceCode;
 }
Пример #20
0
 private Price(PriceCode priceCode, IFees fees, IPoints points)
 {
     _fees     = fees;
     _points   = points;
     PriceCode = priceCode;
 }