mirror of
https://github.com/Sea-Haven-Industries/shoc-backend.git
synced 2026-10-02 03:53:24 +00:00
34 lines
1.4 KiB
C#
34 lines
1.4 KiB
C#
|
|
using System.Linq.Expressions;
|
||
|
|
using Data.SeaHavenIndustries;
|
||
|
|
|
||
|
|
namespace SeaHaven.DataServices.Helpers
|
||
|
|
{
|
||
|
|
/// <summary>
|
||
|
|
/// The single definition of an uplift's amount: the NTE increase being requested.
|
||
|
|
/// The two creation paths store different meanings in RequestedNTE. Vendor-portal
|
||
|
|
/// requests store the requested new NTE total, so the amount is RequestedNTE minus
|
||
|
|
/// the NTE at request time. Work-order requests store the increase itself. Vendor
|
||
|
|
/// sessions have no identity user, so createdby is null only on vendor-portal rows.
|
||
|
|
/// </summary>
|
||
|
|
public static class UpliftAmount
|
||
|
|
{
|
||
|
|
/// <summary>Translatable form for EF queries and aggregates.</summary>
|
||
|
|
public static readonly Expression<Func<DispatchUpliftRequest, decimal>> ForQuery =
|
||
|
|
u => u.createdby == null
|
||
|
|
? u.RequestedNTE - (u.CurrentNTE ?? 0m)
|
||
|
|
: u.RequestedNTE;
|
||
|
|
|
||
|
|
private static readonly Func<DispatchUpliftRequest, decimal> Compiled = ForQuery.Compile();
|
||
|
|
|
||
|
|
public static decimal Of(DispatchUpliftRequest request) => Compiled(request);
|
||
|
|
|
||
|
|
public static decimal Of(string? createdBy, decimal requestedNte, decimal? currentNte) =>
|
||
|
|
Compiled(new DispatchUpliftRequest
|
||
|
|
{
|
||
|
|
createdby = createdBy,
|
||
|
|
RequestedNTE = requestedNte,
|
||
|
|
CurrentNTE = currentNte,
|
||
|
|
});
|
||
|
|
}
|
||
|
|
}
|