34 lines
1.3 KiB
C#
34 lines
1.3 KiB
C#
using SmallSoftwareContracts.Exceptions;
|
|
using SmallSoftwareContracts.Extensions;
|
|
using SmallSoftwareContracts.Infrastructure;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using System.Threading.Tasks;
|
|
|
|
namespace SmallSoftwareContracts.DataModels;
|
|
|
|
public class SupplyDataModel(string id, string storageId, DateTime supplyDate, List<SupplySoftwareDataModel> softwares) : IValidation
|
|
{
|
|
public string Id { get; private set; } = id;
|
|
public string StorageId { get; private set; } = storageId;
|
|
public DateTime SupplyDate { get; private set; } = supplyDate;
|
|
|
|
public List<SupplySoftwareDataModel> Softwares { get; private set; } = softwares;
|
|
|
|
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 (StorageId.IsEmpty())
|
|
throw new ValidationException("Field StorageId is empty");
|
|
if (!StorageId.IsGuid())
|
|
throw new ValidationException("The value in the field StorageId is not a unique identifier");
|
|
|
|
if ((Softwares?.Count ?? 0) == 0)
|
|
throw new ValidationException("The sale must include products");
|
|
}
|
|
} |