forked from slavaxom9k/PIBD-23_Fomichev_V.S._MagicCarpet
46 lines
1.7 KiB
C#
46 lines
1.7 KiB
C#
using MagicCarpetContracts.Exceptions;
|
|
using MagicCarpetContracts.Extensions;
|
|
using MagicCarpetContracts.Infrastructure;
|
|
using MagicCarpetContracts.Mapper;
|
|
using MagicCarpetContracts.Resources;
|
|
using Microsoft.Extensions.Localization;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using System.Threading.Tasks;
|
|
|
|
namespace MagicCarpetContracts.DataModels;
|
|
|
|
internal 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.ToUniversalTime();
|
|
|
|
[AlternativeName("EmployeeSalary")]
|
|
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 SalaryDataModel() : this(string.Empty, DateTime.Now, 0) { }
|
|
|
|
public void Validate(IStringLocalizer<Messages> localizer)
|
|
{
|
|
if (EmployeeId.IsEmpty())
|
|
throw new ValidationException(string.Format(localizer["ValidationExceptionMessageEmptyField"], "EmployeeId"));
|
|
|
|
if (!EmployeeId.IsGuid())
|
|
throw new ValidationException(string.Format(localizer["ValidationExceptionMessageNotAId"], "EmployeeId"));
|
|
|
|
if (Salary <= 0)
|
|
throw new ValidationException(string.Format(localizer["ValidationExceptionMessageLessOrEqualZero"], "Salary"));
|
|
}
|
|
}
|