35 lines
1.3 KiB
C#
35 lines
1.3 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using CandyHouseBase.Enums;
|
|
using CandyHouseBase.Exceptions;
|
|
using CandyHouseBase.Extensions;
|
|
using CandyHouseBase.Infrastructure;
|
|
|
|
namespace CandyHouseBase.DataModels
|
|
{
|
|
public class StorageDataModel : IValidation
|
|
{
|
|
public string Id { get; set; }
|
|
public string Title { get; set; }
|
|
public StorageType StorageType { get; set; }
|
|
public List<IngredientDataModel> Ingredients { get; set; }
|
|
|
|
public StorageDataModel(string id, string title, StorageType storageType, List<IngredientDataModel> ingredients)
|
|
{
|
|
Id = id;
|
|
Title = title;
|
|
StorageType = storageType;
|
|
Ingredients = ingredients;
|
|
}
|
|
|
|
public void Validate()
|
|
{
|
|
if (Id.IsEmpty()) throw new ValidationException("Field Id is empty");
|
|
if (!Id.IsGuid()) throw new ValidationException("Invalid Id format");
|
|
if (Title.IsEmpty()) throw new ValidationException("Field Title is empty");
|
|
if (!Enum.IsDefined(typeof(StorageType), StorageType))
|
|
throw new ValidationException($"Invalid StorageType: {StorageType}");
|
|
if (Ingredients == null) throw new ValidationException($"Ingredients is null");
|
|
}
|
|
}
|
|
} |