33 lines
1.3 KiB
C#
33 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 StorageDataModel(string id, string storageName, string address, bool isDeleted, List<StorageSoftwareDataModel> softwares) : IValidation
|
|
{
|
|
public string Id { get; private set; } = id;
|
|
public string StorageName { get; private set; } = storageName;
|
|
public string Address { get; private set; } = address;
|
|
public bool IsDeleted { get; private set; } = isDeleted;
|
|
public List<StorageSoftwareDataModel> 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 (StorageName.IsEmpty())
|
|
throw new ValidationException("Field StorageName is empty");
|
|
if (Address.IsEmpty())
|
|
throw new ValidationException("Field Address is empty");
|
|
if ((Softwares?.Count ?? 0) == 0)
|
|
throw new ValidationException("The sale must include products");
|
|
}
|
|
} |