PIbd-21_Alekseev_I.S._Confe.../Confectionery/ConfectioneryListImplement/Models/Pastry.cs

54 lines
1.5 KiB
C#
Raw Permalink Normal View History

2024-03-23 19:50:45 +04:00
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
};
}
}