ISEbd-21.Gordeev.I.V.SushiB.../SushiBar/SushiBarDatabaseImplement/Models/Ingredient.cs

64 lines
1.6 KiB
C#
Raw Permalink Normal View History

2024-04-03 16:59:01 +04:00
using SushiBarContracts.BindingModels;
using SushiBarContracts.ViewModels;
using SushiBarDataModels.Models;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
namespace SushiBarDatabaseImplement.Models
{
public class Ingredient : IIngredientModel
{
public int Id { get; private set; }
[Required]
public string IngredientName { get; private set; } = string.Empty;
[Required]
public double Cost { get; set; }
[ForeignKey("IngredientId")]
public virtual List<SushiIngredient> SushiIngredients { get; set; } = new();
public static Ingredient? Create(IngredientBindingModel model)
{
if (model == null)
{
return null;
}
return new Ingredient()
{
Id = model.Id,
IngredientName = model.IngredientName,
Cost = model.Cost
};
}
public static Ingredient Create(IngredientViewModel model)
{
return new Ingredient
{
Id = model.Id,
IngredientName = model.IngredientName,
Cost = model.Cost
};
}
public void Update(IngredientBindingModel model)
{
if (model == null)
{
return;
}
IngredientName = model.IngredientName;
Cost = model.Cost;
}
public IngredientViewModel GetViewModel => new()
{
Id = Id,
IngredientName = IngredientName,
Cost = Cost
};
}
}