Files
Pibd-21_Semin_D.A._SmallSof…/SmallSoftwareProject/SmallSoftwareContracts/DataModels/SoftwareHistoryDataModel.cs
2025-03-27 06:55:34 +04:00

38 lines
1.3 KiB
C#

using SmallSoftwareContracts.Exceptions;
using SmallSoftwareContracts.Extensions;
using SmallSoftwareContracts.Infrastructure;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace SmallSoftwareContracts.DataModels;
public class SoftwareHistoryDataModel(string softwareId, double oldPrice) : IValidation
{
private readonly SoftwareDataModel? _software;
public string SoftwareId { get; private set; } = softwareId;
public double OldPrice { get; private set; } = oldPrice;
public DateTime ChangeDate { get; private set; } = DateTime.UtcNow;
public string SoftwareName => _software?.SoftwareName ?? string.Empty;
public SoftwareHistoryDataModel(string softwareId, double oldPrice, DateTime
changeDate, SoftwareDataModel software) : this(softwareId, oldPrice)
{
ChangeDate = changeDate;
_software = software;
}
public void Validate()
{
if (SoftwareId.IsEmpty())
throw new ValidationException("Field SoftwareId is empty");
if (!SoftwareId.IsGuid())
throw new ValidationException("The value in the field SoftwareId is not a unique identifier");
if (OldPrice <= 0)
throw new ValidationException("Field OldPrice is less than or equal to 0");
}
}