34 lines
1.4 KiB
C#
34 lines
1.4 KiB
C#
using Microsoft.Extensions.Localization;
|
|
using CandyHouseContracts.Exceptions;
|
|
using CandyHouseContracts.Extensions;
|
|
using CandyHouseContracts.Infrastructure;
|
|
using CandyHouseContracts.Resources;
|
|
|
|
namespace CandyHouseContracts.DataModels;
|
|
|
|
internal class ManufacturerDataModel(string id, string manufacturerName, string? prevManufacturerName, string? prevPrevManufacturerName) : IValidation
|
|
{
|
|
public string Id { get; private set; } = id;
|
|
|
|
public string ManufacturerName { get; private set; } = manufacturerName;
|
|
|
|
public string? PrevManufacturerName { get; private set; } = prevManufacturerName;
|
|
|
|
public string? PrevPrevManufacturerName { get; private set; } = prevPrevManufacturerName;
|
|
|
|
public ManufacturerDataModel() : this(string.Empty, string.Empty, null, null) { }
|
|
|
|
public ManufacturerDataModel(string id, string manufacturerName) : this(id, manufacturerName, null, null) { }
|
|
|
|
public void Validate(IStringLocalizer<Messages> localizer)
|
|
{
|
|
if (Id.IsEmpty())
|
|
throw new ValidationException(string.Format(localizer["ValidationExceptionMessageEmptyField"], "Id"));
|
|
|
|
if (!Id.IsGuid())
|
|
throw new ValidationException(string.Format(localizer["ValidationExceptionMessageNotAId"], "Id"));
|
|
|
|
if (ManufacturerName.IsEmpty())
|
|
throw new ValidationException(string.Format(localizer["ValidationExceptionMessageEmptyField"], "ManufacturerName"));
|
|
}
|
|
} |