PIbd-22_Shabunov_O.A._SushiBar/SushiBarDatabaseImplement/Models/Ingredient.cs
2024-05-16 17:13:55 +04:00

49 lines
1.2 KiB
C#

using SushiBarContracts.BindingModels;
using SushiBarContracts.ViewModels;
using System.ComponentModel.DataAnnotations;
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();
public static Ingredient? Create(IngredientBindingModel Model)
{
return new Ingredient()
{
IngredientName = Model.IngredientName,
Unit = Model.Unit,
Cost = Model.Cost,
};
}
public void Update(IngredientBindingModel Model)
{
Cost = Model.Cost;
}
public IngredientViewModel ViewModel => new()
{
Id = Id,
IngredientName = IngredientName,
Unit = Unit,
Cost = Cost,
};
}
}