39 lines
1.2 KiB
C#
Raw Normal View History

2025-02-03 01:12:40 +04:00
using TheCyclopsContracts.Enums;
using TheCyclopsContracts.Exceptions;
using TheCyclopsContracts.Extensions;
using TheCyclopsContracts.Infrastructure;
namespace TheCyclopsContracts.DataModels;
public class ComponentDataModel(string id, string componentName,
ComponentType componentType, double price, bool isDeleted) : IValidation
{
public string Id { get; private set; } = id;
public string ComponentName { get; private set; } = componentName;
public ComponentType ComponentType { get; private set; } = componentType;
public double Price { get; private set; } = price;
public bool IsDeleted { get; private set; } = isDeleted;
public void Validate()
{
if (Id.IsEmpty())
throw new ValidationException("Field Id is empty");
if (!Id.IsGuid())
throw new ValidationException("The value in the field Id is not a unique identifier");
if (ComponentName.IsEmpty())
throw new ValidationException("Field ComponentName is empty");
if (ComponentType == ComponentType.None)
throw new ValidationException("Field ComponentType is empty");
if (Price <= 0)
throw new ValidationException("Field Price is less than or equal to 0");
}
}