2023-02-07 13:00:02 +04:00
|
|
|
|
using FoodOrdersContracts.BindingModels;
|
|
|
|
|
using FoodOrdersContracts.ViewModels;
|
|
|
|
|
using FoodOrdersDataModels.Models;
|
|
|
|
|
|
|
|
|
|
namespace FoodOrdersListImplement.Models
|
|
|
|
|
{
|
|
|
|
|
public class Dish : IDishModel
|
|
|
|
|
{
|
|
|
|
|
public int Id { get; private set; }
|
|
|
|
|
public string DishName { get; private set; } = string.Empty;
|
2023-02-12 10:11:34 +04:00
|
|
|
|
public double Price { get; private set; }
|
|
|
|
|
public Dictionary<int, (IComponentModel, int)> DishComponents
|
|
|
|
|
{
|
|
|
|
|
get;
|
|
|
|
|
private set;
|
|
|
|
|
} = new Dictionary<int, (IComponentModel, int)>();
|
2023-02-07 13:00:02 +04:00
|
|
|
|
public static Dish? Create(DishBindingModel? model)
|
|
|
|
|
{
|
|
|
|
|
if (model == null)
|
|
|
|
|
{
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
return new Dish()
|
|
|
|
|
{
|
|
|
|
|
Id = model.Id,
|
|
|
|
|
DishName = model.DishName,
|
2023-02-12 10:11:34 +04:00
|
|
|
|
Price = model.Price,
|
|
|
|
|
DishComponents = model.DishComponents
|
2023-02-07 13:00:02 +04:00
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
public void Update(DishBindingModel? model)
|
|
|
|
|
{
|
|
|
|
|
if (model == null)
|
|
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
DishName = model.DishName;
|
2023-02-12 10:11:34 +04:00
|
|
|
|
Price = model.Price;
|
|
|
|
|
DishComponents = model.DishComponents;
|
2023-02-07 13:00:02 +04:00
|
|
|
|
}
|
|
|
|
|
public DishViewModel GetViewModel => new()
|
|
|
|
|
{
|
|
|
|
|
Id = Id,
|
|
|
|
|
DishName = DishName,
|
2023-02-12 10:11:34 +04:00
|
|
|
|
Price = Price,
|
|
|
|
|
DishComponents = DishComponents
|
2023-02-07 13:00:02 +04:00
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
}
|