PIbd-23_Zargarov_M.A._Pizzeria/Pizzeria/PizzeriaListImplement/Models/Pizza.cs

56 lines
1.5 KiB
C#
Raw Normal View History

2023-02-19 23:38:16 +04:00
using PizzeriaContracts.BindingModels;
using PizzeriaContracts.ViewModels;
using PizzeriaDataModels;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace PizzeriaListImplement.Models
{
public class Pizza : IPizzaModel
{
public int Id { get; private set; }
2023-03-05 22:35:21 +04:00
public string PizzaName { get; private set; } = string.Empty;
2023-02-19 23:38:16 +04:00
public double Price { get; private set; }
2023-03-05 22:35:21 +04:00
public Dictionary<int, (IComponentModel, int)> PizzaComponents
2023-02-19 23:38:16 +04:00
{
get;
private set;
} = new Dictionary<int, (IComponentModel, int)>();
public static Pizza? Create(PizzaBindingModel? model)
{
if (model == null)
{
return null;
}
return new Pizza()
{
Id = model.Id,
2023-03-05 22:35:21 +04:00
PizzaName = model.PizzaName,
2023-02-19 23:38:16 +04:00
Price = model.Price,
2023-03-05 22:35:21 +04:00
PizzaComponents = model.PizzaComponents
2023-02-19 23:38:16 +04:00
};
}
public void Update(PizzaBindingModel? model)
{
if (model == null)
{
return;
}
2023-03-05 22:35:21 +04:00
PizzaName = model.PizzaName;
2023-02-19 23:38:16 +04:00
Price = model.Price;
2023-03-05 22:35:21 +04:00
PizzaComponents = model.PizzaComponents;
2023-02-19 23:38:16 +04:00
}
public PizzaViewModel GetViewModel => new()
{
Id = Id,
2023-03-05 22:35:21 +04:00
PizzaName = PizzaName,
2023-02-19 23:38:16 +04:00
Price = Price,
2023-03-05 22:35:21 +04:00
PizzaComponents = PizzaComponents
2023-02-19 23:38:16 +04:00
};
}
}