using CanteenDataModels.Models; using System; using System.Collections.Generic; using System.ComponentModel.DataAnnotations.Schema; using System.ComponentModel.DataAnnotations; using System.Linq; using System.Text; using System.Threading.Tasks; using CanteenContracts.BindingModels; using CanteenContracts.ViewModels; namespace CanteenDatabaseImplement.Models { public class Ingredient : IIngredientModel { public int Id { get; private set; } [Required] public string IngredientName { get; private set; } = string.Empty; [Required] public double IngredientCost { get; set; } [ForeignKey("IngredientId")] public virtual List DishIngredients { get; set; } = new(); public static Ingredient? Create(IngredientBindingModel model) { if (model == null) { return null; } return new Ingredient() { Id = model.Id, IngredientName = model.IngredientName, IngredientCost = model.IngredientCost }; } public static Ingredient Create(IngredientViewModel model) { return new Ingredient { Id = model.Id, IngredientName = model.IngredientName, IngredientCost = model.IngredientCost }; } public void Update(IngredientBindingModel model) { if (model == null) { return; } IngredientName = model.IngredientName; IngredientCost = model.IngredientCost; } public IngredientViewModel GetViewModel => new() { Id = Id, IngredientName = IngredientName, IngredientCost = IngredientCost }; } }