40 lines
1.3 KiB
C#
40 lines
1.3 KiB
C#
using CandyHouseContracts.Exceptions;
|
|
using CandyHouseContracts.Extensions;
|
|
using CandyHouseContracts.Infrastructure;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using System.Threading.Tasks;
|
|
|
|
namespace CandyHouseContracts.DataModels;
|
|
|
|
public class SalaryDataModel(string employeeId, DateTime salaryDate, double employeeSalary) : IValidation
|
|
{
|
|
private readonly EmployeeDataModel? _employee;
|
|
public string EmployeeId { get; private set; } = employeeId;
|
|
|
|
public DateTime SalaryDate { get; private set; } = salaryDate;
|
|
|
|
public double Salary { get; private set; } = employeeSalary;
|
|
|
|
public string EmployeeFIO => _employee?.FIO ?? string.Empty;
|
|
|
|
public SalaryDataModel(string employeeId, DateTime salaryDate, double employeeSalary, EmployeeDataModel employee) : this(employeeId, salaryDate, employeeSalary)
|
|
{
|
|
_employee = employee;
|
|
}
|
|
|
|
public void Validate()
|
|
{
|
|
if (EmployeeId.IsEmpty())
|
|
throw new ValidationException("Field EmployeeId is empty");
|
|
|
|
if (!EmployeeId.IsGuid())
|
|
throw new ValidationException("The value in the field EmployeeId is not a unique identifier");
|
|
|
|
if (Salary <= 0)
|
|
throw new ValidationException("Field Salary is less than or equal to 0");
|
|
}
|
|
}
|