Last active
February 8, 2018 23:23
-
-
Save avegaraju/21eecbcd7a29887fe31157072ca13ebf to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class Order | |
{ | |
//properties removed for brevity | |
public decimal Checkout() | |
{ | |
decimal amountToPay = 0; | |
foreach (var orderLine in this.OrderLines) | |
{ | |
decimal discountAmount = GetApplicableDiscount(orderLine); | |
decimal productPriceAfterDiscount = ApplyDiscount(orderLine, discountAmount); | |
amountToPay += productPriceAfterDiscount; | |
} | |
if (Customer.IsPrivilegeCustomer) | |
ApplyAdditionalDiscount(); | |
return _orderAmount = amountToPay; | |
decimal ApplyDiscount(OrderLine orderLine, decimal discountAmount) | |
{ | |
return (orderLine.Price - discountAmount) * orderLine.Quantity; | |
} | |
decimal GetApplicableDiscount(OrderLine orderLine) | |
{ | |
return (orderLine.Price * orderLine.Discount) / 100; | |
} | |
void ApplyAdditionalDiscount() | |
{ | |
amountToPay = (amountToPay * 5) / 100; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment