Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@dsibinski
Last active June 16, 2021 03:32
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 dsibinski/6ada7c2cf888a1e2aba726e919109a7d to your computer and use it in GitHub Desktop.
Save dsibinski/6ada7c2cf888a1e2aba726e919109a7d to your computer and use it in GitHub Desktop.
public class DiscountApplier
{
public int GetDiscountPercentageValue(Product[] products)
{
var discountValue = 0;
if (products.Length == 1) {
return 0;
}
var allProductsQuantity = products.Sum(p => p.Quantity);
if (allProductsQuantity is > 10 and <= 50) {
discountValue += 10;
}
if (allProductsQuantity > 50) {
discountValue += 15;
}
var allProductsPrice = products.Sum(p => p.Quantity * p.Price);
if (allProductsPrice is > 100 and <= 500) {
discountValue += 5;
}
if (allProductsPrice is > 500 and <= 2000) {
discountValue += 10;
}
if (allProductsPrice > 2000) {
discountValue += 25;
}
return discountValue;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment