54 lines
1.5 KiB
C#
54 lines
1.5 KiB
C#
|
using ConfectioneryContracts.BindingModels;
|
|||
|
using ConfectioneryContracts.ViewModels;
|
|||
|
using ConfectioneryDataModels.Models;
|
|||
|
using System;
|
|||
|
using System.Collections.Generic;
|
|||
|
using System.Linq;
|
|||
|
using System.Text;
|
|||
|
using System.Threading.Tasks;
|
|||
|
|
|||
|
namespace ConfectioneryListImplement.Models
|
|||
|
{
|
|||
|
public class Pastry : IPastryModel
|
|||
|
{
|
|||
|
public int Id { get; private set; }
|
|||
|
public string PastryName { get; private set; } = string.Empty;
|
|||
|
public double Price { get; private set; }
|
|||
|
public Dictionary<int, (IComponentModel, int)> PastryComponents { get; private set; } = new Dictionary<int, (IComponentModel, int)>();
|
|||
|
|
|||
|
public static Pastry? Create(PastryBindingModel? model)
|
|||
|
{
|
|||
|
if (model == null)
|
|||
|
{
|
|||
|
return null;
|
|||
|
}
|
|||
|
return new Pastry()
|
|||
|
{
|
|||
|
Id = model.Id,
|
|||
|
PastryName = model.PastryName,
|
|||
|
Price = model.Price,
|
|||
|
PastryComponents = model.PastryComponents,
|
|||
|
};
|
|||
|
}
|
|||
|
|
|||
|
public void Update(PastryBindingModel? model)
|
|||
|
{
|
|||
|
if (model == null)
|
|||
|
{
|
|||
|
return;
|
|||
|
}
|
|||
|
PastryName = model.PastryName;
|
|||
|
Price = model.Price;
|
|||
|
PastryComponents = model.PastryComponents;
|
|||
|
}
|
|||
|
|
|||
|
public PastryViewModel GetViewModel => new()
|
|||
|
{
|
|||
|
Id = Id,
|
|||
|
PastryName = PastryName,
|
|||
|
Price = Price,
|
|||
|
PastryComponents = PastryComponents
|
|||
|
};
|
|||
|
}
|
|||
|
}
|