2
This commit is contained in:
parent
4d376bc58f
commit
c03408fdde
7
Pizzeria/AbstractShopFileImplement/Models/Order.cs
Normal file
7
Pizzeria/AbstractShopFileImplement/Models/Order.cs
Normal file
@ -0,0 +1,7 @@
|
||||
using PizzeriaDataModels.Models;
|
||||
namespace AbstractShopFileImplement.Models
|
||||
{
|
||||
internal class Order : IOrderModel
|
||||
{
|
||||
}
|
||||
}
|
@ -10,8 +10,21 @@ namespace AbstractShopFileImplement.Models
|
||||
public int Id { get; private set; }
|
||||
public string PizzaName { get; private set; } = string.Empty;
|
||||
public double Price { get; private set; }
|
||||
public Dictionary<int, (IComponentModel, int)> PizzaComponents { get; private set; } = new Dictionary<int, (IComponentModel, int)>();
|
||||
public static Pizza? Create(PizzaBindingModel? model)
|
||||
public Dictionary<int, int> Components { get; private set; } = new();
|
||||
private Dictionary<int, (IComponentModel, int)>? _PizzaComponents = null;
|
||||
public Dictionary<int, (IComponentModel, int)> PizzaComponents
|
||||
{
|
||||
get
|
||||
{
|
||||
if (_PizzaComponents == null)
|
||||
{
|
||||
//var source = DataFileSingleton.GetInstance();
|
||||
//_PizzaComponents = Components.ToDictionary(x => x.Key, y =>((source.Components.FirstOrDefault(z => z.Id == y.Key) as IComponentModel)!,y.Value));
|
||||
}
|
||||
return _PizzaComponents;
|
||||
}
|
||||
}
|
||||
public static Pizza? Create(PizzaBindingModel model)
|
||||
{
|
||||
if (model == null)
|
||||
{
|
||||
@ -22,29 +35,24 @@ namespace AbstractShopFileImplement.Models
|
||||
Id = model.Id,
|
||||
PizzaName = model.PizzaName,
|
||||
Price = model.Price,
|
||||
PizzaComponents = model.PizzaComponents
|
||||
Components = model.PizzaComponents.ToDictionary(x => x.Key, x => x.Value.Item2)
|
||||
};
|
||||
}
|
||||
public static Product? Create(XElement element)
|
||||
public static Pizza? Create(XElement element)
|
||||
{
|
||||
if (element == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
return new Product()
|
||||
return new Pizza()
|
||||
{
|
||||
Id = Convert.ToInt32(element.Attribute("Id")!.Value),
|
||||
ProductName = element.Element("ProductName")!.Value,
|
||||
PizzaName = element.Element("PizzaName")!.Value,
|
||||
Price = Convert.ToDouble(element.Element("Price")!.Value),
|
||||
Components =
|
||||
element.Element("ProductComponents")!.Elements("ProductComponent")
|
||||
.ToDictionary(x =>
|
||||
Convert.ToInt32(x.Element("Key")?.Value), x =>
|
||||
Convert.ToInt32(x.Element("Value")?.Value))
|
||||
Components = element.Element("PizzaComponents")!.Elements("PizzaComponent").ToDictionary(x =>Convert.ToInt32(x.Element("Key")?.Value), x =>Convert.ToInt32(x.Element("Value")?.Value))
|
||||
};
|
||||
}
|
||||
|
||||
public void Update(PizzaBindingModel? model)
|
||||
public void Update(PizzaBindingModel model)
|
||||
{
|
||||
if (model == null)
|
||||
{
|
||||
@ -52,7 +60,8 @@ namespace AbstractShopFileImplement.Models
|
||||
}
|
||||
PizzaName = model.PizzaName;
|
||||
Price = model.Price;
|
||||
PizzaComponents = model.PizzaComponents;
|
||||
Components = model.PizzaComponents.ToDictionary(x => x.Key, x =>x.Value.Item2);
|
||||
_PizzaComponents = null;
|
||||
}
|
||||
public PizzaViewModel GetViewModel => new()
|
||||
{
|
||||
@ -61,5 +70,14 @@ namespace AbstractShopFileImplement.Models
|
||||
Price = Price,
|
||||
PizzaComponents = PizzaComponents
|
||||
};
|
||||
public XElement GetXElement => new("Pizza",
|
||||
new XAttribute("Id", Id),
|
||||
new XElement("PizzaName", PizzaName),
|
||||
new XElement("Price", Price.ToString()),
|
||||
new XElement("PizzaComponents", Components.Select(x => new XElement("PizzaComponent",
|
||||
new XElement("Key", x.Key),
|
||||
new XElement("Value", x.Value)))
|
||||
.ToArray()));
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -2,13 +2,6 @@
|
||||
using PizzeriaContracts.ViewModels;
|
||||
using PizzeriaDataModels.Enums;
|
||||
using PizzeriaDataModels.Models;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics;
|
||||
using System.Linq;
|
||||
using System.Reflection;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace PizzeriaListImplement.Models
|
||||
{
|
||||
|
Loading…
Reference in New Issue
Block a user