39 lines
1.3 KiB
C#

using NorthBridgeContract.Exceptions;
using NorthBridgeContract.Extensions;
using NorthBridgeContract.Infrastructure;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace NorthBridgeContract.DataModels
{
public class SupplyDataModel(string id, string storageId, DateTime date, List<ComponentInSupplyDataModel> components) : IValidation
{
public string Id { get; private set; } = id;
public string StorageId { get; private set; } = storageId;
public DateTime Date { get; private set; } = date;
public List<ComponentInSupplyDataModel> Components { get; private set; } = components;
public void Validate()
{
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 (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 (Components.Count == 0)
throw new ValidationException("At least 1 component is needed");
}
}
}