dimanche 24 juillet 2022

Best structure for multiple payment rules based on employee type in C#

I have an Employees class:

public class StaffMember
{
    public int Id { get; set; }
    public string ContractType {get; set;}
    public string JobTitle {get; set;}
    public int DaysWorked {get; set;}
}

and I have a PaymentRule class:

public class PaymentRule
{
    public string ContractType {get; set;}
    public string JobTitle {get; set;}
    public int DailyRate { get; set; }
    public int MaxPayAmount { get; set; }
    public int MinPayAmount { get; set; }
    public int MaxWorkedDays { get; set; }
    public int MinWorkedDays{ get; set; }
}

now, there are multiple payment rules which depend on both ContractType and JobTitle, for example, one rule might be as follows:

 if ContractType = full time and jobTitle = sales and DaysWorked > MinDaysWorked: pay 100$
    else pay DaysWorked * DailyRate

there are many other rules like this with changing structure, I want have a form where I search with the member ID and the member is retrieved from database then the rule is also retrieved and applied and I get the payment for the employee.

The problem is the rules are complex, so I want a structured and generalized way to implement the current rules and extend more rules without the code becoming spaghetti.

I understand that maybe I need to implement an interface and extend it, but I can't wrap my head around the full image

Aucun commentaire:

Enregistrer un commentaire