39 lines
1.2 KiB
C#

using IcecreamVan.Enums;
using IcecreamVan.Extensions;
using IcecreamVan.Infrastructure;
using IcecreamVan.Exceptions;
namespace IcecreamVan.DataModels;
public class PostDataModel(string id, string postName, PostType postType, double salary, bool isActual, DateTime changeDate) : IValidation
{
public string Id { get; private set; } = id;
public string PostName { get; private set; } = postName;
public PostType PostType { get; private set; } = postType;
public double Salary { get; private set; } = salary;
public bool IsActual { get; private set; } = isActual;
public DateTime ChangeDate { get; private set; } = changeDate;
public void Validate()
{
if (Id.IsEmpty())
throw new ValidationException("Field ID is empty");
if (!Id.IsGuid())
throw new ValidationException("The ID value is NOT a unique identifier");
if (PostName.IsEmpty())
throw new ValidationException("Name is empty");
if (PostType == PostType.None)
throw new ValidationException("Type is empty");
if (Salary <= 0)
throw new ValidationException("Salary is empty");
}
}