Skip to content

Instantly share code, notes, and snippets.

@avegaraju
Last active February 8, 2018 23:23
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save avegaraju/21eecbcd7a29887fe31157072ca13ebf to your computer and use it in GitHub Desktop.
Save avegaraju/21eecbcd7a29887fe31157072ca13ebf to your computer and use it in GitHub Desktop.
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