Merge branch 'refs/heads/lab-1-hard' into lab-2-hard-no-logic
# Conflicts: # CandyHouseSolution/CandyHouseBase/DataModels/StorageDataModel.cs
This commit is contained in:
@@ -0,0 +1,35 @@
|
||||
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");
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user