From a798cf5d69c2f99be80b60f6f0357ed51a8926b1 Mon Sep 17 00:00:00 2001 From: malimova Date: Fri, 15 Mar 2024 10:52:30 +0400 Subject: [PATCH] =?UTF-8?q?=D0=94=D0=BE=D0=B4=D0=B5=D0=BB=D0=B0=D0=BB?= =?UTF-8?q?=D0=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../ConfectioneryFileImplement/DataFileSingleton.cs | 9 +++------ .../ConfectioneryFileImplement/OrderStorage.cs | 6 +++--- Confectionery/ConfectioneryFileImplement/Pastry.cs | 10 +++------- 3 files changed, 9 insertions(+), 16 deletions(-) diff --git a/Confectionery/ConfectioneryFileImplement/DataFileSingleton.cs b/Confectionery/ConfectioneryFileImplement/DataFileSingleton.cs index b54cfeb..939a2cc 100644 --- a/Confectionery/ConfectioneryFileImplement/DataFileSingleton.cs +++ b/Confectionery/ConfectioneryFileImplement/DataFileSingleton.cs @@ -37,8 +37,7 @@ namespace ConfectioneryFileImplement 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) + private static List? LoadData(string filename, string xmlNodeName, Func selectFunction) { if (File.Exists(filename)) { @@ -47,13 +46,11 @@ namespace ConfectioneryFileImplement } return new List(); } - private static void SaveData(List data, string filename, string - xmlNodeName, Func selectFunction) + private static void SaveData(List data, string filename, string xmlNodeName, Func selectFunction) { if (data != null) { - new XDocument(new XElement(xmlNodeName, - data.Select(selectFunction).ToArray())).Save(filename); + new XDocument(new XElement(xmlNodeName, data.Select(selectFunction).ToArray())).Save(filename); } } } diff --git a/Confectionery/ConfectioneryFileImplement/OrderStorage.cs b/Confectionery/ConfectioneryFileImplement/OrderStorage.cs index 66954d5..0ca29d8 100644 --- a/Confectionery/ConfectioneryFileImplement/OrderStorage.cs +++ b/Confectionery/ConfectioneryFileImplement/OrderStorage.cs @@ -83,10 +83,10 @@ namespace ConfectioneryFileImplement.Implements { return null; } - var pizza = source.Pastrys.FirstOrDefault(x => x.Id == model.PastryId); - if (pizza != null) + var pastry = source.Pastrys.FirstOrDefault(x => x.Id == model.PastryId); + if (pastry != null) { - model.PastryName = pizza.PastryName; + model.PastryName = pastry.PastryName; } return model; } diff --git a/Confectionery/ConfectioneryFileImplement/Pastry.cs b/Confectionery/ConfectioneryFileImplement/Pastry.cs index a82b204..7611b91 100644 --- a/Confectionery/ConfectioneryFileImplement/Pastry.cs +++ b/Confectionery/ConfectioneryFileImplement/Pastry.cs @@ -58,11 +58,8 @@ namespace ConfectioneryFileImplement.Models Id = Convert.ToInt32(element.Attribute("Id")!.Value), PastryName = element.Element("PastryName")!.Value, Price = Convert.ToDouble(element.Element("Price")!.Value), - Components = -element.Element("PastryComponents")!.Elements("PastryComponent") - .ToDictionary(x => -Convert.ToInt32(x.Element("Key")?.Value), x => -Convert.ToInt32(x.Element("Value")?.Value)) + Components = element.Element("PastryComponents")!.Elements("PastryComponent").ToDictionary + (x => Convert.ToInt32(x.Element("Key")?.Value), x => Convert.ToInt32(x.Element("Value")?.Value)) }; } public void Update(PastryBindingModel model) @@ -73,8 +70,7 @@ Convert.ToInt32(x.Element("Value")?.Value)) } PastryName = model.PastryName; Price = model.Price; - Components = model.PastryComponents.ToDictionary(x => x.Key, x => - x.Value.Item2); + Components = model.PastryComponents.ToDictionary(x => x.Key, x => x.Value.Item2); _pastryComponents = null; } public PastryViewModel GetViewModel => new()