Calculating business logic Here's a messy C# method used to calculate some business logic.

Does anybody have any suggestions on how I can optimise this code? I'm asking in case there are bad practices, improvements or functions within .NET/LINQ which I'm missing.

private static decimal GetRecurringCostEquiv(List&lt;QuotationItemViewModel&gt; items)
{

    var discVal = GetDiscounts(items, (int)RecordEnums.ProductClassification.Service);

    decimal? currentRecurringCosts = GetRecurringCost(items).Value;

    decimal? result = 0.00M;

    decimal highestContractTerm = items.Where(x =&gt; x.ProductTypeId == (int)RecordEnums.ProductClassification.Service).Select(y =&gt; y.RecurringTerm).Max() ?? 0;

    if ((discVal &gt; 0) &amp;&amp; (highestContractTerm &gt; 0))
    {
        var calc = items.Where(x =&gt; x.ProductTypeId == (int)RecordEnums.ProductClassification.Service).Select(y =&gt; y.RecurringCostCore * y.Quantity);
        decimal total = calc.Sum() ?? 0;
        decimal totalOverTerm = total * highestContractTerm;
        decimal totalOverTermMinusDiscounts = totalOverTerm - discVal;
        result = totalOverTermMinusDiscounts / highestContractTerm;
    }
    else
    {
        result = currentRecurringCosts;
    }

    return result ?? 0.00M;
}
There's two things that I'm seeing right off the bat.


Don't use "magic integers" where you can be using Enums.  GetDiscounts should probably receive an enum, not an int:

var discVal = GetDiscounts(items, RecordEnums.ProductClassification.Service);
You don't need to Select then Max.  Just using Max will give you the desired outcome.

decimal highestContractTerm = items.Where(x =&gt; x.ProductTypeId == (int)RecordEnums.ProductClassification.Service).Max(y =&gt; y.RecurringTerm ?? 0;