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

39 lines
1.6 KiB
C#

using SmallSoftwareContracts.Exceptions;
using SmallSoftwareContracts.Extensions;
using SmallSoftwareContracts.Infrastructure;
namespace SmallSoftwareContracts.DataModels;
public class InstallationRequestDataModel(string softwareId, string requestId, int count, double price) : IValidation
{
private readonly SoftwareDataModel? _software;
public string SoftwareId { get; private set; } = softwareId;
public string RequestId { get; private set; } = requestId;
public int Count { get; private set; } = count;
public double Price { get; private set; } = price;
public string SoftwareName => _software?.SoftwareName ?? string.Empty;
public InstallationRequestDataModel(string saleId, string softwareId, int count, double price, SoftwareDataModel software) : this(saleId, softwareId, count, price)
{
_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 (RequestId.IsEmpty())
throw new ValidationException("Field RequestId is empty");
if (!RequestId.IsGuid())
throw new ValidationException("The value in the field RequestId is not a unique identifier");
if (Count <= 0)
throw new ValidationException("Field Count is less than or equal to 0");
if (Price <= 0)
throw new ValidationException("Field Price is less than or equal to 0");
}
}