diff --git a/Confectionery/ConfectioneryFileImplement/DataFileSingleton.cs b/Confectionery/ConfectioneryFileImplement/DataFileSingleton.cs index 76cee5d..b54cfeb 100644 --- a/Confectionery/ConfectioneryFileImplement/DataFileSingleton.cs +++ b/Confectionery/ConfectioneryFileImplement/DataFileSingleton.cs @@ -29,14 +29,13 @@ namespace ConfectioneryFileImplement "Components", x => x.GetXElement); public void SavePastrys() => SaveData(Pastrys, PastryFileName, "Pastrys", x => x.GetXElement); - public void SaveOrders() { } + public void SaveOrders() => SaveData(Orders, OrderFileName, + "Orders", x => x.GetXElement); private DataFileSingleton() { - Components = LoadData(ComponentFileName, "Component", x => - Component.Create(x)!)!; - Pastrys = LoadData(PastryFileName, "Pastry", x => - Pastry.Create(x)!)!; - Orders = new List(); + Components = LoadData(ComponentFileName, "Component", x => Component.Create(x)!)!; + Pastrys = LoadData(PastryFileName, "Pastry", x => Pastry.Create(x)!)!; + Orders = LoadData(OrderFileName, "Order", x => Order.Create(x)!)!; } private static List? LoadData(string filename, string xmlNodeName, Func selectFunction) diff --git a/Confectionery/ConfectioneryFileImplement/Order.cs b/Confectionery/ConfectioneryFileImplement/Order.cs index 6bad7b9..26a2c15 100644 --- a/Confectionery/ConfectioneryFileImplement/Order.cs +++ b/Confectionery/ConfectioneryFileImplement/Order.cs @@ -4,9 +4,9 @@ using ConfectioneryContracts.BindingModels; using ConfectioneryContracts.ViewModels; using System.Xml.Linq; -namespace ConfectioneryFileImplement +namespace ConfectioneryFileImplement.Models { - public class Order + public class Order : IOrderModel { public int Id { get; private set; } public int PastryId { get; private set; } diff --git a/Confectionery/ConfectioneryFileImplement/OrderStorage.cs b/Confectionery/ConfectioneryFileImplement/OrderStorage.cs index 4159a26..66954d5 100644 --- a/Confectionery/ConfectioneryFileImplement/OrderStorage.cs +++ b/Confectionery/ConfectioneryFileImplement/OrderStorage.cs @@ -2,6 +2,7 @@ using ConfectioneryContracts.SearchModels; using ConfectioneryContracts.StoragesContracts; using ConfectioneryContracts.ViewModels; +using ConfectioneryFileImplement.Models; using System; using System.Collections.Generic; using System.Linq; @@ -82,10 +83,10 @@ namespace ConfectioneryFileImplement.Implements { return null; } - var pastry = source.Pastrys.FirstOrDefault(x => x.Id == model.PastryId); - if (pastry != null) + var pizza = source.Pastrys.FirstOrDefault(x => x.Id == model.PastryId); + if (pizza != null) { - model.PastryName = pastry.PastryName; + model.PastryName = pizza.PastryName; } return model; } diff --git a/Confectionery/ConfectioneryFileImplement/Pastry.cs b/Confectionery/ConfectioneryFileImplement/Pastry.cs index c53c0cb..a82b204 100644 --- a/Confectionery/ConfectioneryFileImplement/Pastry.cs +++ b/Confectionery/ConfectioneryFileImplement/Pastry.cs @@ -17,19 +17,19 @@ namespace ConfectioneryFileImplement.Models public double Price { get; private set; } public Dictionary Components { get; private set; } = new(); - private Dictionary? _productComponents = null; + private Dictionary? _pastryComponents = null; public Dictionary PastryComponents { get { - if (_productComponents == null) + if (_pastryComponents == null) { var source = DataFileSingleton.GetInstance(); - _productComponents = Components.ToDictionary(x => x.Key, y => + _pastryComponents = Components.ToDictionary(x => x.Key, y => ((source.Components.FirstOrDefault(z => z.Id == y.Key) as IComponentModel)!, y.Value)); } - return _productComponents; + return _pastryComponents; } } public static Pastry? Create(PastryBindingModel model) @@ -75,7 +75,7 @@ Convert.ToInt32(x.Element("Value")?.Value)) Price = model.Price; Components = model.PastryComponents.ToDictionary(x => x.Key, x => x.Value.Item2); - _productComponents = null; + _pastryComponents = null; } public PastryViewModel GetViewModel => new() { diff --git a/Confectionery/ConfectioneryView/FormCreateOrder.cs b/Confectionery/ConfectioneryView/FormCreateOrder.cs index c2665e7..835c490 100644 --- a/Confectionery/ConfectioneryView/FormCreateOrder.cs +++ b/Confectionery/ConfectioneryView/FormCreateOrder.cs @@ -92,9 +92,9 @@ namespace ConfectioneryView try { int id = Convert.ToInt32(comboBoxPastry.SelectedValue); - var product = _logicP.ReadElement(new PastrySearchModel { Id = id }); + var pastry = _logicP.ReadElement(new PastrySearchModel { Id = id }); int count = Convert.ToInt32(textBoxCount.Text); - textBoxSum.Text = Math.Round(count * (product?.Price ?? 0), 2).ToString(); + textBoxSum.Text = Math.Round(count * (pastry?.Price ?? 0), 2).ToString(); _logger.LogInformation("Расчет суммы заказа"); } catch (Exception ex)