From c32c65f4a50d04a6f1572ecdedb65ba80f880edb Mon Sep 17 00:00:00 2001 From: bulatova_karina Date: Mon, 25 Mar 2024 21:23:46 +0400 Subject: [PATCH] lab2 --- .../Models/Computer.cs | 33 ++++++++----------- 1 file changed, 14 insertions(+), 19 deletions(-) diff --git a/ComputersShop/ComputersShopFileImplement/Models/Computer.cs b/ComputersShop/ComputersShopFileImplement/Models/Computer.cs index eedad8e..afaa4d9 100644 --- a/ComputersShop/ComputersShopFileImplement/Models/Computer.cs +++ b/ComputersShop/ComputersShopFileImplement/Models/Computer.cs @@ -16,8 +16,7 @@ namespace ComputersShopFileImplement.Models public string ComputerName { get; private set; } = string.Empty; public double Price { get; private set; } public Dictionary Components { get; private set; } = new(); - private Dictionary? _computerComponents = - null; + private Dictionary? _computerComponents = null; public Dictionary ComputerComponents { get @@ -43,8 +42,7 @@ namespace ComputersShopFileImplement.Models Id = model.Id, ComputerName = model.ComputerName, Price = model.Price, - Components = model.ComputerComponents.ToDictionary(x => x.Key, x - => x.Value.Item2) + Components = model.ComputerComponents.ToDictionary(x => x.Key, x => x.Value.Item2) }; } public static Computer? Create(XElement element) @@ -58,8 +56,11 @@ namespace ComputersShopFileImplement.Models Id = Convert.ToInt32(element.Attribute("Id")!.Value), ComputerName = element.Element("ComputerName")!.Value, Price = Convert.ToDouble(element.Element("Price")!.Value), - Components = element.Element("ComputerComponents")!.Elements("ComputerComponent") - .ToDictionary(x => Convert.ToInt32(x.Element("Key")?.Value), x => Convert.ToInt32(x.Element("Value")?.Value)) + Components = + element.Element("ComputerComponents")!.Elements("ComputerComponent") + .ToDictionary(x => + Convert.ToInt32(x.Element("Key")?.Value), x => + Convert.ToInt32(x.Element("Value")?.Value)) }; } public void Update(ComputerBindingModel model) @@ -70,8 +71,7 @@ namespace ComputersShopFileImplement.Models } ComputerName = model.ComputerName; Price = model.Price; - Components = model.ComputerComponents.ToDictionary(x => x.Key, x => - x.Value.Item2); + Components = model.ComputerComponents.ToDictionary(x => x.Key, x => x.Value.Item2); _computerComponents = null; } public ComputerViewModel GetViewModel => new() @@ -82,17 +82,12 @@ namespace ComputersShopFileImplement.Models ComputerComponents = ComputerComponents }; public XElement GetXElement => new("Computer", - new XAttribute("Id", Id), - new XElement("ComputerName", ComputerName), - new XElement("Price", Price.ToString()), - new XElement("ComputerComponents", Components.Select(x => - new XElement("ComputerComponent", - - new XElement("Key", x.Key), - - new XElement("Value", x.Value))) - - .ToArray())); + new XAttribute("Id", Id), + new XElement("ComputerName", ComputerName), + new XElement("Price", Price.ToString()), + new XElement("ComputerComponents", Components.Select(x => + new XElement("ComputerComponent", new XElement("Key", x.Key), + new XElement("Value", x.Value))).ToArray())); } }