41 lines
1.9 KiB
C#
41 lines
1.9 KiB
C#
using Microsoft.Extensions.Localization;
|
|
using SmallSoftwareContracts.Exceptions;
|
|
using SmallSoftwareContracts.Extensions;
|
|
using SmallSoftwareContracts.Infrastructure;
|
|
using SmallSoftwareContracts.Resources;
|
|
|
|
namespace SmallSoftwareContracts.DataModels;
|
|
|
|
internal 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(IStringLocalizer<Messages> localizer)
|
|
{
|
|
if (SoftwareId.IsEmpty())
|
|
throw new ValidationException(string.Format(localizer["ValidationExceptionMessageEmptyField"], "SoftwareId"));
|
|
if (!SoftwareId.IsGuid())
|
|
throw new ValidationException(string.Format(localizer["ValidationExceptionMessageNotAId"], "SoftwareId"));
|
|
if (RequestId.IsEmpty())
|
|
throw new ValidationException(string.Format(localizer["ValidationExceptionMessageEmptyField"], "RequestId"));
|
|
if (!RequestId.IsGuid())
|
|
throw new ValidationException(string.Format(localizer["ValidationExceptionMessageNotAId"], "RequestId"));
|
|
if (Count <= 0)
|
|
throw new ValidationException(string.Format(localizer["ValidationExceptionMessageLessOrEqualZero"], "Count"));
|
|
if (Price <= 0)
|
|
throw new ValidationException(string.Format(localizer["ValidationExceptionMessageLessOrEqualZero"], "Price"));
|
|
}
|
|
}
|