2025-02-04 16:40:18 +03:00
|
|
|
|
using PapaCarloContracts.Exceptions;
|
|
|
|
|
using PapaCarloContracts.Extensions;
|
|
|
|
|
using PapaCarloContracts.infrastructure;
|
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Linq;
|
|
|
|
|
using System.Text;
|
|
|
|
|
using System.Threading.Tasks;
|
|
|
|
|
|
|
|
|
|
namespace PapaCarloContracts.DataModels;
|
|
|
|
|
|
2025-02-04 18:23:58 +03:00
|
|
|
|
public class CuttingDataModel(string id, string workerId, string blankId, bool isCancel, List<CuttingProductDataModel> products) : IValidation
|
2025-02-04 16:40:18 +03:00
|
|
|
|
{
|
|
|
|
|
public string Id { get; private set; } = id;
|
|
|
|
|
|
|
|
|
|
public string WorkerId { get; private set; } = workerId;
|
|
|
|
|
|
|
|
|
|
public DateTime CutDate { get; private set; } = DateTime.UtcNow;
|
2025-02-04 18:23:58 +03:00
|
|
|
|
public string BlankId { get; private set; } = blankId;
|
2025-02-04 16:40:18 +03:00
|
|
|
|
public bool IsCancel { get; private set; } = isCancel;
|
|
|
|
|
|
2025-02-04 18:23:58 +03:00
|
|
|
|
public List<CuttingProductDataModel> Products { get; private set; } = products;
|
2025-02-04 16:40:18 +03:00
|
|
|
|
|
|
|
|
|
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 (WorkerId.IsEmpty())
|
|
|
|
|
throw new ValidationException("Field WorkerId is empty");
|
|
|
|
|
|
|
|
|
|
if (!WorkerId.IsGuid())
|
|
|
|
|
throw new ValidationException("The value in the field WorkerId is not a unique identifier");
|
|
|
|
|
|
2025-02-04 18:23:58 +03:00
|
|
|
|
if (BlankId.IsEmpty())
|
|
|
|
|
throw new ValidationException("Field BlankId is empty");
|
|
|
|
|
|
|
|
|
|
if (!BlankId.IsGuid())
|
|
|
|
|
throw new ValidationException("The value in the field BlankId is not a unique identifier");
|
|
|
|
|
new ValidationException("Field Sum is less than or equal to 0");
|
2025-02-04 16:40:18 +03:00
|
|
|
|
|
2025-02-04 18:23:58 +03:00
|
|
|
|
if ((Products?.Count ?? 0) == 0)
|
2025-02-04 16:40:18 +03:00
|
|
|
|
throw new ValidationException("The cut must include blanks");
|
|
|
|
|
}
|
|
|
|
|
}
|