44 lines
1.5 KiB
C#
44 lines
1.5 KiB
C#
using TwoFromTheCaseContracts.Exceptions;
|
|
using TwoFromTheCaseContracts.Extensions;
|
|
using TwoFromTheCaseContracts.Infrastructure;
|
|
|
|
namespace TwoFromTheCaseContracts.DataModels;
|
|
|
|
public class WorkDataModel(string id, string premisesId, double price, bool isCancel, List<WorkerWorkDataModel> workers) : IValidation
|
|
{
|
|
public string Id { get; private set; } = id;
|
|
|
|
public string PremisesId { get; private set; } = premisesId;
|
|
|
|
public double Price { get; private set; } = price;
|
|
|
|
public DateTime StartDate { get; private set; } = DateTime.UtcNow;
|
|
|
|
public DateTime FinishDate { get; private set; } = DateTime.UtcNow;
|
|
|
|
public bool IsCancel { get; private set; } = isCancel;
|
|
|
|
public List<WorkerWorkDataModel> Workers { get; private set; } = workers;
|
|
|
|
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 (PremisesId.IsEmpty())
|
|
throw new ValidationException("Field PremisesId is empty");
|
|
|
|
if (!PremisesId.IsGuid())
|
|
throw new ValidationException("The value in the field PremisesId is not a unique identifier");
|
|
|
|
if (Price <= 0)
|
|
throw new ValidationException("Field Price is less than or equal to 0");
|
|
|
|
if ((Workers?.Count ?? 0) == 0)
|
|
throw new ValidationException("The work must include workers");
|
|
}
|
|
}
|