2023-03-06 10:20:01 +04:00
|
|
|
|
using ConfectioneryContracts.BindingModels;
|
|
|
|
|
using ConfectioneryContracts.ViewModels;
|
|
|
|
|
using ConfectioneryDataModels.Models;
|
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.ComponentModel.DataAnnotations;
|
|
|
|
|
using System.ComponentModel.DataAnnotations.Schema;
|
|
|
|
|
using System.Linq;
|
2023-05-14 00:56:36 +04:00
|
|
|
|
using System.Runtime.Serialization;
|
2023-03-06 10:20:01 +04:00
|
|
|
|
using System.Text;
|
|
|
|
|
using System.Threading.Tasks;
|
|
|
|
|
|
|
|
|
|
namespace ConfectioneryDataBaseImplement.Models
|
|
|
|
|
{
|
2023-05-14 00:56:36 +04:00
|
|
|
|
[DataContract]
|
2023-03-06 10:20:01 +04:00
|
|
|
|
public class Ingredient : IIngredientModel
|
|
|
|
|
{
|
2023-05-14 00:56:36 +04:00
|
|
|
|
[DataMember]
|
2023-03-06 10:20:01 +04:00
|
|
|
|
public int Id { get; private set; }
|
2023-05-14 00:56:36 +04:00
|
|
|
|
[DataMember]
|
2023-03-06 10:20:01 +04:00
|
|
|
|
[Required]
|
|
|
|
|
public string IngredientName { get; private set; } = string.Empty;
|
2023-05-14 00:56:36 +04:00
|
|
|
|
[DataMember]
|
2023-03-06 10:20:01 +04:00
|
|
|
|
[Required]
|
|
|
|
|
public double Cost { get; set; }
|
|
|
|
|
[ForeignKey("IngredientId")]
|
|
|
|
|
public virtual List<PastryIngredient> PastryIgredients { 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
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
}
|