Simplify Tax Calculation

converted foreach if into where statement
This commit is contained in:
s459315 2022-07-24 00:10:49 +02:00
parent 2b2897e128
commit ea46f598bc

View File

@ -117,13 +117,9 @@ namespace RMWPFUserInterface.ViewModels
decimal taxAmount = 0;
decimal TaxRate = _configHelper.GetTaxRate()/100;
foreach (var item in Cart)
{
if (item.Product.IsTaxable)
{
taxAmount += (item.Product.RetailPrice * item.QuantityInCart * TaxRate);
}
}
taxAmount = Cart
.Where(x => x.Product.IsTaxable)
.Sum(x => x.Product.RetailPrice * x.QuantityInCart * TaxRate);
return taxAmount;
}