2024-05-15 21:37:18 +04:00
|
|
|
|
using SushiBarContracts.BindingModels;
|
2024-05-16 17:13:55 +04:00
|
|
|
|
using SushiBarContracts.ViewModels;
|
2024-05-15 21:37:18 +04:00
|
|
|
|
using System.ComponentModel.DataAnnotations;
|
2024-05-15 20:43:24 +04:00
|
|
|
|
using System.ComponentModel.DataAnnotations.Schema;
|
|
|
|
|
|
|
|
|
|
namespace SushiBarDatabaseImplement.Models
|
|
|
|
|
{
|
|
|
|
|
public class Ingredient
|
|
|
|
|
{
|
|
|
|
|
[Key]
|
|
|
|
|
public int Id { get; set; }
|
|
|
|
|
|
|
|
|
|
[Required]
|
|
|
|
|
public string IngredientName { get; set; } = string.Empty;
|
|
|
|
|
|
|
|
|
|
[Required]
|
|
|
|
|
public string Unit { get; set; } = string.Empty;
|
|
|
|
|
|
|
|
|
|
[Required]
|
|
|
|
|
public double Cost { get; set; }
|
|
|
|
|
|
|
|
|
|
[ForeignKey("IngredientId")]
|
|
|
|
|
public virtual List<DishIngredient> DishIngredients { get; set; } = new();
|
2024-05-15 21:37:18 +04:00
|
|
|
|
|
|
|
|
|
public static Ingredient? Create(IngredientBindingModel Model)
|
|
|
|
|
{
|
|
|
|
|
return new Ingredient()
|
|
|
|
|
{
|
|
|
|
|
IngredientName = Model.IngredientName,
|
2024-05-16 17:13:55 +04:00
|
|
|
|
Unit = Model.Unit,
|
|
|
|
|
Cost = Model.Cost,
|
2024-05-15 21:37:18 +04:00
|
|
|
|
};
|
|
|
|
|
}
|
2024-05-16 17:13:55 +04:00
|
|
|
|
|
|
|
|
|
public void Update(IngredientBindingModel Model)
|
2024-05-15 21:37:18 +04:00
|
|
|
|
{
|
2024-05-16 17:13:55 +04:00
|
|
|
|
Cost = Model.Cost;
|
2024-05-15 21:37:18 +04:00
|
|
|
|
}
|
2024-05-16 17:13:55 +04:00
|
|
|
|
|
|
|
|
|
public IngredientViewModel ViewModel => new()
|
2024-05-15 21:37:18 +04:00
|
|
|
|
{
|
2024-05-16 17:13:55 +04:00
|
|
|
|
Id = Id,
|
|
|
|
|
IngredientName = IngredientName,
|
|
|
|
|
Unit = Unit,
|
|
|
|
|
Cost = Cost,
|
2024-05-15 21:37:18 +04:00
|
|
|
|
};
|
2024-05-15 20:43:24 +04:00
|
|
|
|
}
|
|
|
|
|
}
|