47 lines
1.4 KiB
C#
Raw Normal View History

2024-02-24 21:32:11 +04:00
using DinerContracts.BindingModels;
using DinerContracts.ViewModels;
using DinerDataModels.Models;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace DinerListImplement.Models
{
internal class Snack : ISnackModel
{
2024-03-02 15:11:38 +04:00
public string ProductName { get; private set; } = string.Empty;
2024-02-24 21:32:11 +04:00
public double Price { get; private set; }
public Dictionary<int, (IFoodModel, int)> ProductComponents { get; private set; } =
new Dictionary<int, (IFoodModel, int)>();
public int ID { get; private set; }
public static Snack? Create(SnackBindingModel? model) {
if (model == null) return null;
return new Snack() {
ID = model.ID,
ProductName = model.ProductName,
Price = model.Price,
ProductComponents = model.ProductComponents
};
}
public void Update(SnackBindingModel? model) {
if (model == null) return;
ProductName = model.ProductName;
Price = model.Price;
ProductComponents = model.ProductComponents;
}
public SnackViewModel GetViewModel => new()
{
ID = ID,
ProductName = ProductName,
Price = Price,
ProductComponents = ProductComponents
};
}
}