47 lines
1.4 KiB
C#
Raw Normal View History

2025-02-26 17:00:16 +04:00
using SnowMaidenContracts.Enums;
using SnowMaidenContracts.Exceptions;
using SnowMaidenContracts.Extensions;
using SnowMaidenContracts.Infrastructure;
namespace SnowMaidenContracts.DataModels;
public class PostDataModel(string id, string postId, string postName, PostType postType, double salary, bool isActual, DateTime changeDate) : IValidation
{
public string Id { get; private set; } = id;
public string PostId { get; private set; } = postId;
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 (PostId.IsEmpty())
throw new ValidationException("Field Post ID is empty");
if (!PostId.IsGuid())
throw new ValidationException("The Post 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");
}
}