2025-02-13 18:55:25 +04:00

50 lines
1.8 KiB
C#

using ElectricalRepairServiceContract.Exceptions;
using ElectricalRepairServiceContract.Extensions;
using ElectricalRepairServiceContract.Interfaces;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
namespace ElectricalRepairServiceContract.DataModels
{
public class DetailsDataModel : IValidation
{
public string Id { get; private set; }
public string Name { get; private set; }
public int Count { get; private set; }
public int OldCount { get; private set; }
public DateTime UpdateDate { get; private set; }
public List<DetailDeliveryDataModel>? DetailsDelivery { get; private set; }
public List<DetailsUseDataModel>? DetailsUses { get; private set; }
public DetailsDataModel(string id, string name, int count, int oldCount,
DateTime updateDate, List<DetailDeliveryDataModel>? detailsDelivery, List<DetailsUseDataModel>? detailsUses)
{
Id = id;
Name = name;
Count = count;
OldCount = oldCount;
UpdateDate = updateDate;
DetailsDelivery = detailsDelivery;
DetailsUses = detailsUses;
}
public void Validate()
{
if (Id.IsEmpty())
throw new ValidationException("Field Id is empty");
if (!Id.IsGuid())
throw new ValidationException("The value in the field Id is not a unique identifier");
if (Name.IsEmpty())
throw new ValidationException("Field Description is empty");
if (Count < 0)
throw new ValidationException("The count must be positive");
if (OldCount < 0)
throw new ValidationException("The count must be positive");
}
}
}