diff --git a/Pizzeria/AbstractShopFileImplement/Models/Order.cs b/Pizzeria/AbstractShopFileImplement/Models/Order.cs new file mode 100644 index 0000000..321a8bb --- /dev/null +++ b/Pizzeria/AbstractShopFileImplement/Models/Order.cs @@ -0,0 +1,7 @@ +using PizzeriaDataModels.Models; +namespace AbstractShopFileImplement.Models +{ + internal class Order : IOrderModel + { + } +} diff --git a/Pizzeria/AbstractShopFileImplement/Models/Pizza.cs b/Pizzeria/AbstractShopFileImplement/Models/Pizza.cs index ca42880..7a90738 100644 --- a/Pizzeria/AbstractShopFileImplement/Models/Pizza.cs +++ b/Pizzeria/AbstractShopFileImplement/Models/Pizza.cs @@ -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 PizzaComponents { get; private set; } = new Dictionary(); - public static Pizza? Create(PizzaBindingModel? model) + public Dictionary Components { get; private set; } = new(); + private Dictionary? _PizzaComponents = null; + public Dictionary 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())); } + } diff --git a/Pizzeria/PizzeriaListImplement/Models/Order.cs b/Pizzeria/PizzeriaListImplement/Models/Order.cs index e0eb9c1..ec76f43 100644 --- a/Pizzeria/PizzeriaListImplement/Models/Order.cs +++ b/Pizzeria/PizzeriaListImplement/Models/Order.cs @@ -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 {