36 lines
1.1 KiB
C#
36 lines
1.1 KiB
C#
using CatHasPawsContratcs.Exceptions;
|
|
using CatHasPawsContratcs.Extensions;
|
|
using CatHasPawsContratcs.Infrastructure;
|
|
|
|
namespace CatHasPawsContratcs.DataModels;
|
|
|
|
public class ProductHistoryDataModel(string productId, double oldPrice) : IValidation
|
|
{
|
|
private readonly ProductDataModel? _product;
|
|
|
|
public string ProductId { get; private set; } = productId;
|
|
|
|
public double OldPrice { get; private set; } = oldPrice;
|
|
|
|
public DateTime ChangeDate { get; private set; } = DateTime.UtcNow;
|
|
|
|
public string ProductName => _product?.ProductName ?? string.Empty;
|
|
|
|
public ProductHistoryDataModel(string productId, double oldPrice, DateTime changeDate, ProductDataModel product) : this(productId, oldPrice)
|
|
{
|
|
ChangeDate = changeDate;
|
|
_product = product;
|
|
}
|
|
|
|
public void Validate()
|
|
{
|
|
if (ProductId.IsEmpty())
|
|
throw new ValidationException("Field ProductId is empty");
|
|
|
|
if (!ProductId.IsGuid())
|
|
throw new ValidationException("The value in the field ProductId is not a unique identifier");
|
|
|
|
if (OldPrice <= 0)
|
|
throw new ValidationException("Field OldPrice is less than or equal to 0");
|
|
}
|
|
} |