Last active
June 16, 2021 03:32
-
-
Save dsibinski/6ada7c2cf888a1e2aba726e919109a7d 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 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