37 lines
1.2 KiB
C#
37 lines
1.2 KiB
C#
|
using CandyHouseBase.Exceptions;
|
||
|
using CandyHouseBase.Extensions;
|
||
|
using CandyHouseBase.Infrastructure;
|
||
|
|
||
|
namespace CandyHouseBase.DataModels
|
||
|
{
|
||
|
public class IngredientStockDataModel : IValidation
|
||
|
{
|
||
|
public string IngredientId { get; private set; }
|
||
|
public int Quantity { get; private set; }
|
||
|
|
||
|
public IngredientStockDataModel(string ingredientId, int quantity)
|
||
|
{
|
||
|
IngredientId = ingredientId;
|
||
|
Quantity = quantity;
|
||
|
}
|
||
|
|
||
|
public void Validate()
|
||
|
{
|
||
|
if (!IngredientId.IsGuid()) throw new ValidationException("IngredientId must be a GUID");
|
||
|
if (Quantity < 0) throw new ValidationException("Quantity cannot be negative");
|
||
|
}
|
||
|
|
||
|
public void AddStock(int amount)
|
||
|
{
|
||
|
if (amount <= 0) throw new ValidationException("Added quantity must be positive");
|
||
|
Quantity += amount;
|
||
|
}
|
||
|
|
||
|
public void RemoveStock(int amount)
|
||
|
{
|
||
|
if (amount <= 0) throw new ValidationException("Removed quantity must be positive");
|
||
|
if (amount > Quantity) throw new ValidationException("Not enough stock available");
|
||
|
Quantity -= amount;
|
||
|
}
|
||
|
}
|
||
|
}
|