Files
Core_Be/Domain/DiscountCalculator.cs
Dhananjaya99 bffc9b1686 first commit
2026-09-28 11:44:26 +05:30

20 lines
659 B
C#

namespace Fitness_core_BE.Domain
{
public static class DiscountCalculator
{
public static decimal ComputeDiscountAmount(decimal subtotal, string? discountType, decimal? discountValue)
{
if (string.IsNullOrEmpty(discountType) || discountValue is not decimal value || value <= 0 || subtotal <= 0)
return 0m;
var discount = discountType switch
{
"Percentage" => subtotal * Math.Clamp(value, 0m, 100m) / 100m,
"Flat" => Math.Clamp(value, 0m, subtotal),
_ => 0m
};
return Math.Round(discount, 2);
}
}
}