public static decimal ApplyDiscount(decimal price, AccountStatus accountStatus, int timeOfHavingAccountInYears) { decimal priceAfterDiscount = 0; switch (accountStatus) { case AccountStatus.NotRegistered: priceAfterDiscount = price; break; case AccountStatus.SimpleCustomer: priceAfterDiscount = price.ApplyDiscountForAccountStatus(Constants2.DISCOUNT_FOR_SIMPLE_CUSTOMERS); break; case AccountStatus.ValuableCustomer: priceAfterDiscount = price.ApplyDiscountForAccountStatus(Constants2.DISCOUNT_FOR_VALUABLE_CUSTOMERS); break; case AccountStatus.MostValuableCustomer: priceAfterDiscount = price.ApplyDiscountForAccountStatus(Constants2.DISCOUNT_FOR_MOST_VALUABLE_CUSTOMERS); break; default: throw new NotImplementedException(); } priceAfterDiscount = priceAfterDiscount.ApplyDiscountForTimeOfHavingAccount(timeOfHavingAccountInYears); return(priceAfterDiscount); }
public decimal ApplyDiscount(decimal price, AccountStatus accountStatus, int timeofHavingInYears) { decimal priceAfterDiscount = 0; decimal discountForYearsInPercentage = (timeofHavingInYears > Constants.MAXIMUM_DISCOUNT_VALUE) ? (decimal)Constants.MAXIMUM_DISCOUNT_VALUE / 100 : (decimal)timeofHavingInYears / 100; switch (accountStatus) { case AccountStatus.NotRegistered: priceAfterDiscount = price; break; case AccountStatus.SimpleCustomer: priceAfterDiscount = price.ApplyDiscountForAccountStatus(Constants.DISCOUNT_SIMPLE_CUSTOMER); break; case AccountStatus.MostValuableCustomer: priceAfterDiscount = price.ApplyDiscountForAccountStatus(Constants.DISCOUNT_MOST_VALUABLE_CUSTOMER); break; case AccountStatus.ValuableCustomer: priceAfterDiscount = price.ApplyDiscountForAccountStatus(Constants.DISCOUNT_VALUABLE_CUSTOMER); break; default: throw new NotImplementedException(); } priceAfterDiscount.ApplyDiscountForTimeOfHavingAccount(timeofHavingInYears); return(priceAfterDiscount); }
/// <summary> /// que hicimos: /// creamos metodos de extension, para decimales (para usarlos para el parametro price en este caso) /// de esa forma podemos tener metodos como ApplyDiscountForAccountStatus que sean aplicables a price /// y asi organizar la forma en que los descuentos se aplican y aislar a esta clase de la responsabilidad de saber /// cómo se calculan los descuentos /// </summary> public decimal Calculate(decimal price, AccountStatus accountStatus, int timeOfHavingAccountInYears) { decimal priceAfterDiscount = 0; switch (accountStatus) { case AccountStatus.NotRegistered: priceAfterDiscount = price; break; case AccountStatus.SimpleCustomer: priceAfterDiscount = price.ApplyDiscountForAccountStatus(Constants.DISCOUNT_FOR_SIMPLE_CUSTOMERS) .ApplyDiscountForTimeOfHavingAccount(timeOfHavingAccountInYears); break; case AccountStatus.ValuableCustomer: priceAfterDiscount = price.ApplyDiscountForAccountStatus(Constants.DISCOUNT_FOR_VALUABLE_CUSTOMERS) .ApplyDiscountForTimeOfHavingAccount(timeOfHavingAccountInYears); break; case AccountStatus.MostValuableCustomer: priceAfterDiscount = price.ApplyDiscountForAccountStatus(Constants.DISCOUNT_FOR_MOST_VALUABLE_CUSTOMERS) .ApplyDiscountForTimeOfHavingAccount(timeOfHavingAccountInYears); break; default: throw new InvalidOperationException($"El parametro accountStatus no tiene un valor válido, valor actual: {accountStatus}"); } return(priceAfterDiscount); }
public decimal ApplyDiscount(decimal price, AccountStatus accountStatus, int timeOfHavingAccountInYears) { decimal priceAfterDiscount; switch (accountStatus) { case AccountStatus.NotRegistered: priceAfterDiscount = price; break; case AccountStatus.SimpleCustomer: priceAfterDiscount = price.ApplyDiscountForAccountStatus(constants.DiscountForSimpleCustomers); break; case AccountStatus.ValuableCustomer: priceAfterDiscount = price.ApplyDiscountForAccountStatus(constants.DiscountForValuableCustomers); break; case AccountStatus.MostValuableCustomer: priceAfterDiscount = price.ApplyDiscountForAccountStatus(constants.DiscountForMostValuableCustomers); break; default: throw new NotImplementedException(); } if (accountStatus != AccountStatus.NotRegistered) { priceAfterDiscount = priceAfterDiscount.ApplyDiscountForTimeOfHavingAccount(timeOfHavingAccountInYears); } return(priceAfterDiscount); }