47 lines
1.4 KiB
C#
47 lines
1.4 KiB
C#
|
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
|
|||
|
{
|
|||
|
public string ProductName { get; private set; } = String.Empty;
|
|||
|
|
|||
|
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
|
|||
|
};
|
|||
|
}
|
|||
|
}
|