From 92e0198a9baa786e7a2a40711103234a9ce38e5e Mon Sep 17 00:00:00 2001 From: VictoriaPresnyakova Date: Tue, 7 Feb 2023 13:21:07 +0400 Subject: [PATCH 01/18] =?UTF-8?q?=D1=81=D0=B4=D0=B0=D0=BD=D0=BE!?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- JewelryStore/FormJewels.cs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/JewelryStore/FormJewels.cs b/JewelryStore/FormJewels.cs index bea74a4..5f5f06f 100644 --- a/JewelryStore/FormJewels.cs +++ b/JewelryStore/FormJewels.cs @@ -36,6 +36,8 @@ namespace JewelryStore DataGridView.DataSource = list; DataGridView.Columns["Id"].Visible = false; DataGridView.Columns["JewelName"].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill; + DataGridView.Columns["JewelComponents"].Visible = false; + } _logger.LogInformation("Загрузка компонентов"); -- 2.25.1 From baf03fc366447841a35e4ce1d4b9ab1ec8a1c4f3 Mon Sep 17 00:00:00 2001 From: VictoriaPresnyakova Date: Sun, 19 Feb 2023 20:54:21 +0400 Subject: [PATCH 02/18] component --- JewelryStore/JewelryStore.sln | 14 ++-- JewelryStoreFileImplement/Class1.cs | 7 ++ .../JewelryStoreFileImplement.csproj | 18 +++++ JewelryStoreFileImplement/Models/Component.cs | 71 +++++++++++++++++++ 4 files changed, 106 insertions(+), 4 deletions(-) create mode 100644 JewelryStoreFileImplement/Class1.cs create mode 100644 JewelryStoreFileImplement/JewelryStoreFileImplement.csproj create mode 100644 JewelryStoreFileImplement/Models/Component.cs diff --git a/JewelryStore/JewelryStore.sln b/JewelryStore/JewelryStore.sln index 08fec75..478a62b 100644 --- a/JewelryStore/JewelryStore.sln +++ b/JewelryStore/JewelryStore.sln @@ -5,13 +5,15 @@ VisualStudioVersion = 17.4.33122.133 MinimumVisualStudioVersion = 10.0.40219.1 Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "JewelryStore", "JewelryStore.csproj", "{F1AEB85A-E5E1-4B07-8D6B-E46870480FFA}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "JewelryStoreContracts", "..\JewelryStoreContracts\JewelryStoreContracts.csproj", "{763B1FD7-7D30-4689-869C-1FEAD240B29B}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "JewelryStoreContracts", "..\JewelryStoreContracts\JewelryStoreContracts.csproj", "{763B1FD7-7D30-4689-869C-1FEAD240B29B}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "JewelryStoreDataModels", "..\JewelryStoreDataModels\JewelryStoreDataModels.csproj", "{84BF2156-F821-46F4-8EED-F371084C0129}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "JewelryStoreDataModels", "..\JewelryStoreDataModels\JewelryStoreDataModels.csproj", "{84BF2156-F821-46F4-8EED-F371084C0129}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "JewelryStoreBusinessLogic", "..\JewelryStoreBusinessLogic\JewelryStoreBusinessLogic.csproj", "{DA57067F-F3ED-4B1C-B56F-52856FC2E93D}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "JewelryStoreBusinessLogic", "..\JewelryStoreBusinessLogic\JewelryStoreBusinessLogic.csproj", "{DA57067F-F3ED-4B1C-B56F-52856FC2E93D}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "JewelryStoreListImplement", "..\JewelryStoreListImplement\JewelryStoreListImplement.csproj", "{B8C8AA30-FC16-4331-B456-CD16C3C97B25}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "JewelryStoreListImplement", "..\JewelryStoreListImplement\JewelryStoreListImplement.csproj", "{B8C8AA30-FC16-4331-B456-CD16C3C97B25}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "JewelryStoreFileImplement", "..\JewelryStoreFileImplement\JewelryStoreFileImplement.csproj", "{2906CD1C-4D78-4329-A2E9-8B67E624DD92}" EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution @@ -39,6 +41,10 @@ Global {B8C8AA30-FC16-4331-B456-CD16C3C97B25}.Debug|Any CPU.Build.0 = Debug|Any CPU {B8C8AA30-FC16-4331-B456-CD16C3C97B25}.Release|Any CPU.ActiveCfg = Release|Any CPU {B8C8AA30-FC16-4331-B456-CD16C3C97B25}.Release|Any CPU.Build.0 = Release|Any CPU + {2906CD1C-4D78-4329-A2E9-8B67E624DD92}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {2906CD1C-4D78-4329-A2E9-8B67E624DD92}.Debug|Any CPU.Build.0 = Debug|Any CPU + {2906CD1C-4D78-4329-A2E9-8B67E624DD92}.Release|Any CPU.ActiveCfg = Release|Any CPU + {2906CD1C-4D78-4329-A2E9-8B67E624DD92}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE diff --git a/JewelryStoreFileImplement/Class1.cs b/JewelryStoreFileImplement/Class1.cs new file mode 100644 index 0000000..616b38f --- /dev/null +++ b/JewelryStoreFileImplement/Class1.cs @@ -0,0 +1,7 @@ +namespace JewelryStoreFileImplement +{ + public class Class1 + { + + } +} \ No newline at end of file diff --git a/JewelryStoreFileImplement/JewelryStoreFileImplement.csproj b/JewelryStoreFileImplement/JewelryStoreFileImplement.csproj new file mode 100644 index 0000000..4a8c6d8 --- /dev/null +++ b/JewelryStoreFileImplement/JewelryStoreFileImplement.csproj @@ -0,0 +1,18 @@ + + + + net6.0 + enable + enable + + + + + + + + + + + + diff --git a/JewelryStoreFileImplement/Models/Component.cs b/JewelryStoreFileImplement/Models/Component.cs new file mode 100644 index 0000000..36d6812 --- /dev/null +++ b/JewelryStoreFileImplement/Models/Component.cs @@ -0,0 +1,71 @@ +using JewelryStoreContracts.BindingModels; +using JewelryStoreContracts.ViewModels; +using JewelryStoreDataModels.Models; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Xml.Linq; + +namespace JewelryStoreFieImplement.Models +{ + public class Component : IComponentModel + { + public int Id { get; private set; } + public string ComponentName { get; private set; } = string.Empty; + public double Cost { get; set; } + + public static Component? Create(ComponentBindingModel? model) + { + if (model == null) + { + return null; + } + return new Component() + { + Id = model.Id, + ComponentName = model.ComponentName, + Cost = model.Cost + }; + } + + public static Component? Create(XElement element) + { + if (element == null) + { + return null; + } + return new Component() + { + Id = Convert.ToInt32(element.Attribute("Id")!.Value), + ComponentName = element.Element("ComponentName")!.Value, + Cost = Convert.ToDouble(element.Element("Cost")!.Value) + }; + } + + + public void Update(ComponentBindingModel? model) + { + if (model == null) + { + return; + } + ComponentName = model.ComponentName; + Cost = model.Cost; + } + public ComponentViewModel GetViewModel => new() + { + Id = Id, + ComponentName = ComponentName, + Cost = Cost + }; + + public XElement GetXElement => new("Component", + new XAttribute("Id", Id), + new XElement("ComponentName", ComponentName), + new XElement("Cost", Cost.ToString())); + } +} + + -- 2.25.1 From 837aceeefc6ba1a39f6cac6869007ee3bcded630 Mon Sep 17 00:00:00 2001 From: VictoriaPresnyakova Date: Sun, 19 Feb 2023 21:02:22 +0400 Subject: [PATCH 03/18] product --- JewelryStoreFileImplement/Models/Jewel.cs | 95 +++++++++++++++++++++++ 1 file changed, 95 insertions(+) create mode 100644 JewelryStoreFileImplement/Models/Jewel.cs diff --git a/JewelryStoreFileImplement/Models/Jewel.cs b/JewelryStoreFileImplement/Models/Jewel.cs new file mode 100644 index 0000000..0f171bd --- /dev/null +++ b/JewelryStoreFileImplement/Models/Jewel.cs @@ -0,0 +1,95 @@ +using JewelryStoreDataModels.Models; +using JewelryStoreContracts.ViewModels; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using JewelryStoreContracts.BindingModels; +using System.Xml.Linq; + +namespace JewelryStoreFileImplement.Models +{ + public class Jewel: IJewelModel + { + public int Id { get; private set; } + public string JewelName { get; private set; } = string.Empty; + public double Price { get; private set; } + public Dictionary Components { get; private set; } = new(); + private Dictionary? _productComponents = null; + + public Dictionary JewelComponents + { + get + { + if (_productComponents == null) + { + var source = DataFileSingleton.GetInstance(); + _productComponents = Components.ToDictionary(x => x.Key, y => + ((source.Components.FirstOrDefault(z => z.Id == y.Key) as IComponentModel)!, + y.Value)); + } + return _productComponents; + } + } + + public static Jewel? Create(JewelBindingModel model) + { + if (model == null) + { + return null; + } + return new Jewel() + { + Id = model.Id, + JewelName = model.JewelName, + Price = model.Price, + Components = model.JewelComponents.ToDictionary(x => x.Key, x + => x.Value.Item2) + }; + } + + public static Jewel? Create(XElement element) + { + if (element == null) + { + return null; + } + return new Jewel() + { + Id = Convert.ToInt32(element.Attribute("Id")!.Value), + JewelName = element.Element("JewelName")!.Value, + Price = Convert.ToDouble(element.Element("Price")!.Value), + Components = + element.Element("JewelComponents")!.Elements("JewelComponent").ToDictionary(x => Convert.ToInt32(x.Element("Key")?.Value), x => + Convert.ToInt32(x.Element("Value")?.Value)) + }; + } + + public void Update(JewelBindingModel model) + { + if (model == null) + { + return; + } + JewelName = model.JewelName; + Price = model.Price; + Components = model.JewelComponents.ToDictionary(x => x.Key, x => x.Value.Item2); + _productComponents = null; + } + public JewelViewModel GetViewModel => new() + { + Id = Id, + JewelName = JewelName, + Price = Price, + JewelComponents = JewelComponents + }; + public XElement GetXElement => new("Jewel", + new XAttribute("Id", Id), + new XElement("JewelName", JewelName), + new XElement("Price", Price.ToString()), + new XElement("JewelComponents", Components.Select(x =>new XElement("JewelComponent",new XElement("Key", x.Key), + new XElement("Value", x.Value))).ToArray())); + + } +} -- 2.25.1 From 14f4dc4909ab7cf49d54542a5b38336e5f656b85 Mon Sep 17 00:00:00 2001 From: VictoriaPresnyakova Date: Sun, 19 Feb 2023 21:04:03 +0400 Subject: [PATCH 04/18] Order TODO --- JewelryStoreFileImplement/Models/Order.cs | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) create mode 100644 JewelryStoreFileImplement/Models/Order.cs diff --git a/JewelryStoreFileImplement/Models/Order.cs b/JewelryStoreFileImplement/Models/Order.cs new file mode 100644 index 0000000..5db9adf --- /dev/null +++ b/JewelryStoreFileImplement/Models/Order.cs @@ -0,0 +1,17 @@ +using JewelryStoreContracts.BindingModels; +using JewelryStoreContracts.ViewModels; +using JewelryStoreDataModels.Enums; +using JewelryStoreDataModels.Models; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace JewelryStoreFileImplement.Models +{ + public class Order : IOrderModel // TODO Lab_2 + { + + } +} -- 2.25.1 From 2f29c9b6bd0e80003b5ff904174c6b19f5d3ac86 Mon Sep 17 00:00:00 2001 From: VictoriaPresnyakova Date: Sun, 19 Feb 2023 21:09:56 +0400 Subject: [PATCH 05/18] DataFileSingleton --- JewelryStoreFileImplement/Class1.cs | 7 --- .../DataFileSingleton.cs | 62 +++++++++++++++++++ JewelryStoreFileImplement/Models/Component.cs | 2 +- 3 files changed, 63 insertions(+), 8 deletions(-) delete mode 100644 JewelryStoreFileImplement/Class1.cs create mode 100644 JewelryStoreFileImplement/DataFileSingleton.cs diff --git a/JewelryStoreFileImplement/Class1.cs b/JewelryStoreFileImplement/Class1.cs deleted file mode 100644 index 616b38f..0000000 --- a/JewelryStoreFileImplement/Class1.cs +++ /dev/null @@ -1,7 +0,0 @@ -namespace JewelryStoreFileImplement -{ - public class Class1 - { - - } -} \ No newline at end of file diff --git a/JewelryStoreFileImplement/DataFileSingleton.cs b/JewelryStoreFileImplement/DataFileSingleton.cs new file mode 100644 index 0000000..3ecab76 --- /dev/null +++ b/JewelryStoreFileImplement/DataFileSingleton.cs @@ -0,0 +1,62 @@ +using JewelryStoreFileImplement.Models; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Xml.Linq; + +namespace JewelryStoreFileImplement +{ + public class DataFileSingleton + { + private static DataFileSingleton? instance; + private readonly string ComponentFileName = "Component.xml"; + private readonly string OrderFileName = "Order.xml"; + private readonly string ProductFileName = "Product.xml"; + public List Components { get; private set; } + public List Orders { get; private set; } + public List Products { get; private set; } + public static DataFileSingleton GetInstance() + { + if (instance == null) + { + instance = new DataFileSingleton(); + } + return instance; + } + public void SaveComponents() => SaveData(Components, ComponentFileName, +"Components", x => x.GetXElement); + public void SaveProducts() => SaveData(Products, ProductFileName, + "Products", x => x.GetXElement); + public void SaveOrders() => SaveData(Orders, OrderFileName, "Orders", x + => x.GetXElement); + private DataFileSingleton() + { + Components = LoadData(ComponentFileName, "Component", x => + Component.Create(x)!)!; + Products = LoadData(ProductFileName, "Product", x => + Product.Create(x)!)!; + Orders = LoadData(OrderFileName, "Order", x => Order.Create(x)!)!; + } + private static List? LoadData(string filename, string xmlNodeName, + Func selectFunction) + { + if (File.Exists(filename)) + { + return + XDocument.Load(filename)?.Root?.Elements(xmlNodeName)?.Select(selectFunction)?.ToList(); + } + return new List(); + } + 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); + } + } + } +} diff --git a/JewelryStoreFileImplement/Models/Component.cs b/JewelryStoreFileImplement/Models/Component.cs index 36d6812..634fb12 100644 --- a/JewelryStoreFileImplement/Models/Component.cs +++ b/JewelryStoreFileImplement/Models/Component.cs @@ -8,7 +8,7 @@ using System.Text; using System.Threading.Tasks; using System.Xml.Linq; -namespace JewelryStoreFieImplement.Models +namespace JewelryStoreFileImplement.Models { public class Component : IComponentModel { -- 2.25.1 From ec7dc9e65a4886d7644f3438389bb0d439973ce0 Mon Sep 17 00:00:00 2001 From: VictoriaPresnyakova Date: Sun, 19 Feb 2023 21:10:27 +0400 Subject: [PATCH 06/18] DataFileSingleton --- JewelryStoreFileImplement/DataFileSingleton.cs | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/JewelryStoreFileImplement/DataFileSingleton.cs b/JewelryStoreFileImplement/DataFileSingleton.cs index 3ecab76..c81215e 100644 --- a/JewelryStoreFileImplement/DataFileSingleton.cs +++ b/JewelryStoreFileImplement/DataFileSingleton.cs @@ -29,14 +29,12 @@ namespace JewelryStoreFileImplement "Components", x => x.GetXElement); public void SaveProducts() => SaveData(Products, ProductFileName, "Products", x => x.GetXElement); - public void SaveOrders() => SaveData(Orders, OrderFileName, "Orders", x - => x.GetXElement); + public void SaveOrders() => SaveData(Orders, OrderFileName, "Orders", x => x.GetXElement); private DataFileSingleton() { Components = LoadData(ComponentFileName, "Component", x => Component.Create(x)!)!; - Products = LoadData(ProductFileName, "Product", x => - Product.Create(x)!)!; + Products = LoadData(ProductFileName, "Product", x => Jewel.Create(x)!)!; Orders = LoadData(OrderFileName, "Order", x => Order.Create(x)!)!; } private static List? LoadData(string filename, string xmlNodeName, -- 2.25.1 From ffd07d70da40fc83e4fbc94066a33eb714cebd16 Mon Sep 17 00:00:00 2001 From: VictoriaPresnyakova Date: Sun, 19 Feb 2023 21:19:11 +0400 Subject: [PATCH 07/18] ComponentStorage --- .../Implements/ComponentStorage .cs | 90 +++++++++++++++++++ .../JewelryStoreFileImplement.csproj | 4 - 2 files changed, 90 insertions(+), 4 deletions(-) create mode 100644 JewelryStoreFileImplement/Implements/ComponentStorage .cs diff --git a/JewelryStoreFileImplement/Implements/ComponentStorage .cs b/JewelryStoreFileImplement/Implements/ComponentStorage .cs new file mode 100644 index 0000000..a882b1b --- /dev/null +++ b/JewelryStoreFileImplement/Implements/ComponentStorage .cs @@ -0,0 +1,90 @@ +using JewelryStoreContracts.BindingModels; +using JewelryStoreContracts.SearchModels; +using JewelryStoreContracts.StoragesContracts; +using JewelryStoreContracts.ViewModels; +using JewelryStoreFileImplement.Models; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace JewelryStoreFileImplement.Implements +{ + public class ComponentStorage : IComponentStorage + { + private readonly DataFileSingleton _source; + public ComponentStorage() + { + _source = DataFileSingleton.GetInstance(); + } + public List GetFullList() + { + return _source.Components.Select(x => x.GetViewModel).ToList(); + } + public List GetFilteredList(ComponentSearchModel + model) + { + if (string.IsNullOrEmpty(model.ComponentName)) + { + return new(); + } + return _source.Components + .Where(x => x.ComponentName.Contains(model.ComponentName)) + .Select(x => x.GetViewModel) + .ToList(); + + } + public ComponentViewModel? GetElement(ComponentSearchModel model) + { + if (string.IsNullOrEmpty(model.ComponentName) && !model.Id.HasValue) + { + return null; + } + return _source.Components + .FirstOrDefault(x => + (!string.IsNullOrEmpty(model.ComponentName) && x.ComponentName == model.ComponentName) || + (model.Id.HasValue && x.Id == model.Id))?.GetViewModel; + } + public ComponentViewModel? Insert(ComponentBindingModel model) + { + model.Id = _source.Components.Count > 0 ? _source.Components.Max(x => +x.Id) + 1 : 1; + var newComponent = Component.Create(model); + if (newComponent == null) + { + return null; + } + _source.Components.Add(newComponent); + _source.SaveComponents(); + return newComponent.GetViewModel; + } + + public ComponentViewModel? Update(ComponentBindingModel model) + { + var component = _source.Components.FirstOrDefault(x => x.Id == +model.Id); + if (component == null) + { + return null; + } + component.Update(model); + _source.SaveComponents(); + return component.GetViewModel; + + + } + public ComponentViewModel? Delete(ComponentBindingModel model) + { + var element = _source.Components.FirstOrDefault(x => x.Id ==model.Id); + if (element != null) + { + _source.Components.Remove(element); + _source.SaveComponents(); + return element.GetViewModel; + } + return null; + + } + } +} diff --git a/JewelryStoreFileImplement/JewelryStoreFileImplement.csproj b/JewelryStoreFileImplement/JewelryStoreFileImplement.csproj index 4a8c6d8..783cc4d 100644 --- a/JewelryStoreFileImplement/JewelryStoreFileImplement.csproj +++ b/JewelryStoreFileImplement/JewelryStoreFileImplement.csproj @@ -11,8 +11,4 @@ - - - - -- 2.25.1 From c1fdf0b803af9cba72cf098bdbace2d5d6480a51 Mon Sep 17 00:00:00 2001 From: VictoriaPresnyakova Date: Sun, 19 Feb 2023 21:20:30 +0400 Subject: [PATCH 08/18] Comonent Storage TODO --- .../Implements/ComponentStorage .cs | 76 +----------- .../Implements/JewelStorage.cs | 112 ++++++++++++++++++ 2 files changed, 114 insertions(+), 74 deletions(-) create mode 100644 JewelryStoreFileImplement/Implements/JewelStorage.cs diff --git a/JewelryStoreFileImplement/Implements/ComponentStorage .cs b/JewelryStoreFileImplement/Implements/ComponentStorage .cs index a882b1b..a016dd5 100644 --- a/JewelryStoreFileImplement/Implements/ComponentStorage .cs +++ b/JewelryStoreFileImplement/Implements/ComponentStorage .cs @@ -11,80 +11,8 @@ using System.Threading.Tasks; namespace JewelryStoreFileImplement.Implements { - public class ComponentStorage : IComponentStorage + public class ComponentStorage : IComponentStorage // TODO Lab_2 { - private readonly DataFileSingleton _source; - public ComponentStorage() - { - _source = DataFileSingleton.GetInstance(); - } - public List GetFullList() - { - return _source.Components.Select(x => x.GetViewModel).ToList(); - } - public List GetFilteredList(ComponentSearchModel - model) - { - if (string.IsNullOrEmpty(model.ComponentName)) - { - return new(); - } - return _source.Components - .Where(x => x.ComponentName.Contains(model.ComponentName)) - .Select(x => x.GetViewModel) - .ToList(); - - } - public ComponentViewModel? GetElement(ComponentSearchModel model) - { - if (string.IsNullOrEmpty(model.ComponentName) && !model.Id.HasValue) - { - return null; - } - return _source.Components - .FirstOrDefault(x => - (!string.IsNullOrEmpty(model.ComponentName) && x.ComponentName == model.ComponentName) || - (model.Id.HasValue && x.Id == model.Id))?.GetViewModel; - } - public ComponentViewModel? Insert(ComponentBindingModel model) - { - model.Id = _source.Components.Count > 0 ? _source.Components.Max(x => -x.Id) + 1 : 1; - var newComponent = Component.Create(model); - if (newComponent == null) - { - return null; - } - _source.Components.Add(newComponent); - _source.SaveComponents(); - return newComponent.GetViewModel; - } - - public ComponentViewModel? Update(ComponentBindingModel model) - { - var component = _source.Components.FirstOrDefault(x => x.Id == -model.Id); - if (component == null) - { - return null; - } - component.Update(model); - _source.SaveComponents(); - return component.GetViewModel; - - - } - public ComponentViewModel? Delete(ComponentBindingModel model) - { - var element = _source.Components.FirstOrDefault(x => x.Id ==model.Id); - if (element != null) - { - _source.Components.Remove(element); - _source.SaveComponents(); - return element.GetViewModel; - } - return null; - - } + } } diff --git a/JewelryStoreFileImplement/Implements/JewelStorage.cs b/JewelryStoreFileImplement/Implements/JewelStorage.cs new file mode 100644 index 0000000..e09b4ab --- /dev/null +++ b/JewelryStoreFileImplement/Implements/JewelStorage.cs @@ -0,0 +1,112 @@ +using JewelryStoreContracts.BindingModels; +using JewelryStoreContracts.SearchModels; +using JewelryStoreContracts.StoragesContracts; +using JewelryStoreContracts.ViewModels; +using JewelryStoreListImplement.Models; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace JewelryStoreListImplement.Implements +{ + public class JewelStorage : IJewelStorage // TODO реализовать интерфейс + { + private readonly DataListSingleton _source; + public JewelStorage() + { + _source = DataListSingleton.GetInstance(); + } + public JewelViewModel? Delete(JewelBindingModel model) + { + for (int i = 0; i < _source.Jewels.Count; ++i) + { + if (_source.Jewels[i].Id == model.Id) + { + var element = _source.Jewels[i]; + _source.Jewels.RemoveAt(i); + return element.GetViewModel; + } + } + return null; + } + + public JewelViewModel? GetElement(JewelSearchModel model) + { + if (string.IsNullOrEmpty(model.JewelName) && !model.Id.HasValue) + { + return null; + } + foreach (var jewel in _source.Jewels) + { + if ((!string.IsNullOrEmpty(model.JewelName) && + jewel.JewelName == model.JewelName) || + (model.Id.HasValue && jewel.Id == model.Id)) + { + return jewel.GetViewModel; + } + } + return null; + } + + public List GetFilteredList(JewelSearchModel model) + { + var result = new List(); + if (string.IsNullOrEmpty(model.JewelName)) + { + return result; + } + foreach (var jewel in _source.Jewels) + { + if (jewel.JewelName.Contains(model.JewelName)) + { + result.Add(jewel.GetViewModel); + } + } + return result; + } + + public List GetFullList() + { + var result = new List(); + foreach (var jewel in _source.Jewels) + { + result.Add(jewel.GetViewModel); + } + return result; + } + + public JewelViewModel? Insert(JewelBindingModel model) + { + model.Id = 1; + foreach (var jewel in _source.Jewels) + { + if (model.Id <= jewel.Id) + { + model.Id = jewel.Id + 1; + } + } + var newJewel = Jewel.Create(model); + if (newJewel == null) + { + return null; + } + _source.Jewels.Add(newJewel); + return newJewel.GetViewModel; + } + + public JewelViewModel? Update(JewelBindingModel model) + { + foreach (var jewel in _source.Jewels) + { + if (jewel.Id == model.Id) + { + jewel.Update(model); + return jewel.GetViewModel; + } + } + return null; + } + } +} -- 2.25.1 From 233c432ede4599fd53667647b0b2c3a528b676ba Mon Sep 17 00:00:00 2001 From: VictoriaPresnyakova Date: Sun, 19 Feb 2023 21:21:08 +0400 Subject: [PATCH 09/18] Component Storage --- .../Implements/ComponentStorage .cs | 76 ++++++++++++++++++- 1 file changed, 74 insertions(+), 2 deletions(-) diff --git a/JewelryStoreFileImplement/Implements/ComponentStorage .cs b/JewelryStoreFileImplement/Implements/ComponentStorage .cs index a016dd5..a882b1b 100644 --- a/JewelryStoreFileImplement/Implements/ComponentStorage .cs +++ b/JewelryStoreFileImplement/Implements/ComponentStorage .cs @@ -11,8 +11,80 @@ using System.Threading.Tasks; namespace JewelryStoreFileImplement.Implements { - public class ComponentStorage : IComponentStorage // TODO Lab_2 + public class ComponentStorage : IComponentStorage { - + private readonly DataFileSingleton _source; + public ComponentStorage() + { + _source = DataFileSingleton.GetInstance(); + } + public List GetFullList() + { + return _source.Components.Select(x => x.GetViewModel).ToList(); + } + public List GetFilteredList(ComponentSearchModel + model) + { + if (string.IsNullOrEmpty(model.ComponentName)) + { + return new(); + } + return _source.Components + .Where(x => x.ComponentName.Contains(model.ComponentName)) + .Select(x => x.GetViewModel) + .ToList(); + + } + public ComponentViewModel? GetElement(ComponentSearchModel model) + { + if (string.IsNullOrEmpty(model.ComponentName) && !model.Id.HasValue) + { + return null; + } + return _source.Components + .FirstOrDefault(x => + (!string.IsNullOrEmpty(model.ComponentName) && x.ComponentName == model.ComponentName) || + (model.Id.HasValue && x.Id == model.Id))?.GetViewModel; + } + public ComponentViewModel? Insert(ComponentBindingModel model) + { + model.Id = _source.Components.Count > 0 ? _source.Components.Max(x => +x.Id) + 1 : 1; + var newComponent = Component.Create(model); + if (newComponent == null) + { + return null; + } + _source.Components.Add(newComponent); + _source.SaveComponents(); + return newComponent.GetViewModel; + } + + public ComponentViewModel? Update(ComponentBindingModel model) + { + var component = _source.Components.FirstOrDefault(x => x.Id == +model.Id); + if (component == null) + { + return null; + } + component.Update(model); + _source.SaveComponents(); + return component.GetViewModel; + + + } + public ComponentViewModel? Delete(ComponentBindingModel model) + { + var element = _source.Components.FirstOrDefault(x => x.Id ==model.Id); + if (element != null) + { + _source.Components.Remove(element); + _source.SaveComponents(); + return element.GetViewModel; + } + return null; + + } } } -- 2.25.1 From 0f9159140893b2da742eee71cb3b22ec12226298 Mon Sep 17 00:00:00 2001 From: VictoriaPresnyakova Date: Sun, 19 Feb 2023 21:21:55 +0400 Subject: [PATCH 10/18] JewelStorage TODO --- .../Implements/JewelStorage.cs | 102 +----------------- 1 file changed, 4 insertions(+), 98 deletions(-) diff --git a/JewelryStoreFileImplement/Implements/JewelStorage.cs b/JewelryStoreFileImplement/Implements/JewelStorage.cs index e09b4ab..2fb5632 100644 --- a/JewelryStoreFileImplement/Implements/JewelStorage.cs +++ b/JewelryStoreFileImplement/Implements/JewelStorage.cs @@ -2,111 +2,17 @@ using JewelryStoreContracts.SearchModels; using JewelryStoreContracts.StoragesContracts; using JewelryStoreContracts.ViewModels; -using JewelryStoreListImplement.Models; +using JewelryStoreFileImplement.Models; using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; -namespace JewelryStoreListImplement.Implements +namespace JewelryStoreFileImplement.Implements { - public class JewelStorage : IJewelStorage // TODO реализовать интерфейс + public class JewelStorage : IJewelStorage // TODO Lab_2 { - private readonly DataListSingleton _source; - public JewelStorage() - { - _source = DataListSingleton.GetInstance(); - } - public JewelViewModel? Delete(JewelBindingModel model) - { - for (int i = 0; i < _source.Jewels.Count; ++i) - { - if (_source.Jewels[i].Id == model.Id) - { - var element = _source.Jewels[i]; - _source.Jewels.RemoveAt(i); - return element.GetViewModel; - } - } - return null; - } - - public JewelViewModel? GetElement(JewelSearchModel model) - { - if (string.IsNullOrEmpty(model.JewelName) && !model.Id.HasValue) - { - return null; - } - foreach (var jewel in _source.Jewels) - { - if ((!string.IsNullOrEmpty(model.JewelName) && - jewel.JewelName == model.JewelName) || - (model.Id.HasValue && jewel.Id == model.Id)) - { - return jewel.GetViewModel; - } - } - return null; - } - - public List GetFilteredList(JewelSearchModel model) - { - var result = new List(); - if (string.IsNullOrEmpty(model.JewelName)) - { - return result; - } - foreach (var jewel in _source.Jewels) - { - if (jewel.JewelName.Contains(model.JewelName)) - { - result.Add(jewel.GetViewModel); - } - } - return result; - } - - public List GetFullList() - { - var result = new List(); - foreach (var jewel in _source.Jewels) - { - result.Add(jewel.GetViewModel); - } - return result; - } - - public JewelViewModel? Insert(JewelBindingModel model) - { - model.Id = 1; - foreach (var jewel in _source.Jewels) - { - if (model.Id <= jewel.Id) - { - model.Id = jewel.Id + 1; - } - } - var newJewel = Jewel.Create(model); - if (newJewel == null) - { - return null; - } - _source.Jewels.Add(newJewel); - return newJewel.GetViewModel; - } - - public JewelViewModel? Update(JewelBindingModel model) - { - foreach (var jewel in _source.Jewels) - { - if (jewel.Id == model.Id) - { - jewel.Update(model); - return jewel.GetViewModel; - } - } - return null; - } + } } -- 2.25.1 From ba692fed0c4a50e7d5ab66734c7de75312335faf Mon Sep 17 00:00:00 2001 From: VictoriaPresnyakova Date: Sun, 19 Feb 2023 21:22:52 +0400 Subject: [PATCH 11/18] OrderStorage TODO --- .../Implements/OrderStorage.cs | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) create mode 100644 JewelryStoreFileImplement/Implements/OrderStorage.cs diff --git a/JewelryStoreFileImplement/Implements/OrderStorage.cs b/JewelryStoreFileImplement/Implements/OrderStorage.cs new file mode 100644 index 0000000..d5303d9 --- /dev/null +++ b/JewelryStoreFileImplement/Implements/OrderStorage.cs @@ -0,0 +1,18 @@ +using JewelryStoreContracts.BindingModels; +using JewelryStoreContracts.SearchModels; +using JewelryStoreContracts.StoragesContracts; +using JewelryStoreContracts.ViewModels; +using JewelryStoreFileImplement.Models; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace JewelryStoreFileImplement.Implements +{ + public class OrderStorage : IOrderStorage // TODO Lab_2 + { + + } +} -- 2.25.1 From 8ba6501dca1d34dd2fdef6f113fafdec2bfb3afa Mon Sep 17 00:00:00 2001 From: VictoriaPresnyakova Date: Sun, 19 Feb 2023 21:32:04 +0400 Subject: [PATCH 12/18] Program --- JewelryStore/JewelryStore.csproj | 1 + JewelryStore/Program.cs | 6 +++--- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/JewelryStore/JewelryStore.csproj b/JewelryStore/JewelryStore.csproj index 90bafab..e6930e9 100644 --- a/JewelryStore/JewelryStore.csproj +++ b/JewelryStore/JewelryStore.csproj @@ -16,6 +16,7 @@ + diff --git a/JewelryStore/Program.cs b/JewelryStore/Program.cs index 4a4a47e..df72a59 100644 --- a/JewelryStore/Program.cs +++ b/JewelryStore/Program.cs @@ -1,7 +1,7 @@ using JewelryStoreContracts.BusinessLogicsContracts; using JewelryStoreContracts.StoragesContracts; using JewelryStoreBusinessLogic.BusinessLogics; -using JewelryStoreListImplement.Implements; +using JewelryStoreFileImplement.Implements; using Microsoft.Extensions.DependencyInjection; using System.Drawing; @@ -23,8 +23,8 @@ namespace JewelryStore { // To customize application configuration such as set high DPI //settings or default font, - // see https://aka.ms/applicationconfiguration. - ApplicationConfiguration.Initialize(); + // see https://aka.ms/applicationconfiguration. + ApplicationConfiguration.Initialize(); var services = new ServiceCollection(); ConfigureServices(services); _serviceProvider = services.BuildServiceProvider(); -- 2.25.1 From 0c874c7eeb2a4242ed5a9be19248a1a0a3389150 Mon Sep 17 00:00:00 2001 From: VictoriaPresnyakova Date: Mon, 20 Feb 2023 15:01:34 +0400 Subject: [PATCH 13/18] Order done --- JewelryStore/JewelryStore.csproj | 4 +- .../JewelryStoreBusinessLogic.csproj | 2 +- JewelryStoreFileImplement/Models/Order.cs | 99 ++++++++++++++++++- 3 files changed, 100 insertions(+), 5 deletions(-) diff --git a/JewelryStore/JewelryStore.csproj b/JewelryStore/JewelryStore.csproj index e6930e9..1d74223 100644 --- a/JewelryStore/JewelryStore.csproj +++ b/JewelryStore/JewelryStore.csproj @@ -9,8 +9,8 @@ - - + + diff --git a/JewelryStoreBusinessLogic/JewelryStoreBusinessLogic.csproj b/JewelryStoreBusinessLogic/JewelryStoreBusinessLogic.csproj index 7e1df35..f21c000 100644 --- a/JewelryStoreBusinessLogic/JewelryStoreBusinessLogic.csproj +++ b/JewelryStoreBusinessLogic/JewelryStoreBusinessLogic.csproj @@ -7,7 +7,7 @@ - + diff --git a/JewelryStoreFileImplement/Models/Order.cs b/JewelryStoreFileImplement/Models/Order.cs index 5db9adf..fc8fa48 100644 --- a/JewelryStoreFileImplement/Models/Order.cs +++ b/JewelryStoreFileImplement/Models/Order.cs @@ -7,11 +7,106 @@ using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; +using System.Xml.Linq; namespace JewelryStoreFileImplement.Models { - public class Order : IOrderModel // TODO Lab_2 + public class Order : IOrderModel { - + public int JewelId { get; private set; } + + public string JewelName { get; private set; } = string.Empty; + + public int Count { get; private set; } + + public double Sum { get; private set; } + + public OrderStatus Status { get; private set; } = OrderStatus.Неизвестен; + + public DateTime DateCreate { get; private set; } = DateTime.Now; + + public DateTime? DateImplement { get; private set; } + + public int Id { get; private set; } + + public static Order? Create(OrderBindingModel model) + { + if (model == null) + { + return null; + } + return new Order() + { + Id = model.Id, + JewelId = model.JewelId, + JewelName = model.JewelName, + Count = model.Count, + Sum = model.Sum, + Status = model.Status, + DateCreate = model.DateCreate, + DateImplement = model.DateImplement + }; + } + + public static Order? Create(XElement element) + { + if (element == null) + { + return null; + } + + var order = new Order() + { + Id = Convert.ToInt32(element.Attribute("Id")!.Value), + JewelId = Convert.ToInt32(element.Element("JewelId")!.Value), + JewelName = element.Element("JewelName")!.Value, + Count = Convert.ToInt32(element.Element("Count")!.Value), + Sum = Convert.ToDouble(element.Element("Sum")!.Value), + Status = (OrderStatus)Enum.Parse(typeof(OrderStatus), element.Element("Status")!.Value), + DateCreate = DateTime.ParseExact(element.Element("DateCreate")!.Value, "G", null) + }; + + DateTime.TryParse(element.Element("DateImplement")!.Value, out DateTime dateImpl); + order.DateImplement = dateImpl; + + return order; + } + + public void Update(OrderBindingModel model) + { + if (model == null) + { + return; + } + JewelId = model.JewelId; + JewelName = model.JewelName; + Count = model.Count; + Sum = model.Sum; + Status = model.Status; + DateCreate = model.DateCreate; + DateImplement = model.DateImplement; + } + + public OrderViewModel GetViewModel => new() + { + Id = Id, + JewelId = JewelId, + JewelName = JewelName, + Count = Count, + Sum = Sum, + Status = Status, + DateCreate = DateCreate, + DateImplement = DateImplement + }; + + public XElement GetXElement => new("Order", + new XAttribute("Id", Id), + new XElement("JewelName", JewelName), + new XElement("JewelId", JewelId.ToString()), + new XElement("Count", Count.ToString()), + new XElement("Sum", Sum.ToString()), + new XElement("Status", Status.ToString()), + new XElement("DateCreate", DateCreate.ToString()), + new XElement("DateImplement", DateImplement.ToString())); } } -- 2.25.1 From 10092dcda3e5bfb6eab4f7815e55bc9e074e553e Mon Sep 17 00:00:00 2001 From: VictoriaPresnyakova Date: Mon, 20 Feb 2023 15:08:30 +0400 Subject: [PATCH 14/18] dfs --- .../DataFileSingleton.cs | 24 +++++++------------ 1 file changed, 9 insertions(+), 15 deletions(-) diff --git a/JewelryStoreFileImplement/DataFileSingleton.cs b/JewelryStoreFileImplement/DataFileSingleton.cs index c81215e..73eeacf 100644 --- a/JewelryStoreFileImplement/DataFileSingleton.cs +++ b/JewelryStoreFileImplement/DataFileSingleton.cs @@ -13,10 +13,10 @@ namespace JewelryStoreFileImplement private static DataFileSingleton? instance; private readonly string ComponentFileName = "Component.xml"; private readonly string OrderFileName = "Order.xml"; - private readonly string ProductFileName = "Product.xml"; + private readonly string JewelFileName = "Jewel.xml"; public List Components { get; private set; } public List Orders { get; private set; } - public List Products { get; private set; } + public List Jewels { get; private set; } public static DataFileSingleton GetInstance() { if (instance == null) @@ -25,20 +25,16 @@ namespace JewelryStoreFileImplement } return instance; } - public void SaveComponents() => SaveData(Components, ComponentFileName, -"Components", x => x.GetXElement); - public void SaveProducts() => SaveData(Products, ProductFileName, - "Products", x => x.GetXElement); + public void SaveComponents() => SaveData(Components, ComponentFileName,"Components", x => x.GetXElement); + public void SaveJewels() => SaveData(Jewels, JewelFileName, "Jewels", x => x.GetXElement); public void SaveOrders() => SaveData(Orders, OrderFileName, "Orders", x => x.GetXElement); private DataFileSingleton() { - Components = LoadData(ComponentFileName, "Component", x => - Component.Create(x)!)!; - Products = LoadData(ProductFileName, "Product", x => Jewel.Create(x)!)!; + Components = LoadData(ComponentFileName, "Component", x =>Component.Create(x)!)!; + Jewels = LoadData(JewelFileName, "Jewel", x => Jewel.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 +43,11 @@ namespace JewelryStoreFileImplement } 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); } } } -- 2.25.1 From 0732cc0ede52309c677d77f2077239eb9b285f00 Mon Sep 17 00:00:00 2001 From: VictoriaPresnyakova Date: Mon, 20 Feb 2023 15:09:55 +0400 Subject: [PATCH 15/18] component storage full --- JewelryStoreFileImplement/Implements/ComponentStorage .cs | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/JewelryStoreFileImplement/Implements/ComponentStorage .cs b/JewelryStoreFileImplement/Implements/ComponentStorage .cs index a882b1b..11ec35c 100644 --- a/JewelryStoreFileImplement/Implements/ComponentStorage .cs +++ b/JewelryStoreFileImplement/Implements/ComponentStorage .cs @@ -48,8 +48,7 @@ namespace JewelryStoreFileImplement.Implements } public ComponentViewModel? Insert(ComponentBindingModel model) { - model.Id = _source.Components.Count > 0 ? _source.Components.Max(x => -x.Id) + 1 : 1; + model.Id = _source.Components.Count > 0 ? _source.Components.Max(x =>x.Id) + 1 : 1; var newComponent = Component.Create(model); if (newComponent == null) { @@ -62,8 +61,7 @@ x.Id) + 1 : 1; public ComponentViewModel? Update(ComponentBindingModel model) { - var component = _source.Components.FirstOrDefault(x => x.Id == -model.Id); + var component = _source.Components.FirstOrDefault(x => x.Id ==model.Id); if (component == null) { return null; -- 2.25.1 From 5a5f36b6b9ff2e93d64ffeb382989530f3b9206a Mon Sep 17 00:00:00 2001 From: VictoriaPresnyakova Date: Mon, 20 Feb 2023 15:17:37 +0400 Subject: [PATCH 16/18] order Storage full --- .../Implements/OrderStorage.cs | 78 ++++++++++++++++++- 1 file changed, 77 insertions(+), 1 deletion(-) diff --git a/JewelryStoreFileImplement/Implements/OrderStorage.cs b/JewelryStoreFileImplement/Implements/OrderStorage.cs index d5303d9..40ac71d 100644 --- a/JewelryStoreFileImplement/Implements/OrderStorage.cs +++ b/JewelryStoreFileImplement/Implements/OrderStorage.cs @@ -13,6 +13,82 @@ namespace JewelryStoreFileImplement.Implements { public class OrderStorage : IOrderStorage // TODO Lab_2 { - + private readonly DataFileSingleton source; + + public OrderStorage() + { + source = DataFileSingleton.GetInstance(); + } + + public OrderViewModel? Delete(OrderBindingModel model) + { + var element = source.Orders.FirstOrDefault(x => x.Id == model.Id); + + if (element != null) + { + source.Orders.Remove(element); + source.SaveOrders(); + + return element.GetViewModel; + } + + return null; + } + + public OrderViewModel? GetElement(OrderSearchModel model) + { + if (!model.Id.HasValue) + { + return null; + } + + return source.Orders.FirstOrDefault(x => (model.Id.HasValue && x.Id == model.Id))?.GetViewModel; + } + + public List GetFilteredList(OrderSearchModel model) + { + if (!model.Id.HasValue) + { + return new(); + } + + return source.Orders.Where(x => x.Id == model.Id).Select(x => x.GetViewModel).ToList(); + } + + public List GetFullList() + { + return source.Orders.Select(x => x.GetViewModel).ToList(); + } + + public OrderViewModel? Insert(OrderBindingModel model) + { + model.Id = source.Orders.Count > 0 ? source.Orders.Max(x => x.Id) + 1 : 1; + var newOrder = Order.Create(model); + + if (newOrder == null) + { + return null; + } + + source.Orders.Add(newOrder); + source.SaveOrders(); + + return newOrder.GetViewModel; + } + + public OrderViewModel? Update(OrderBindingModel model) + { + var order = source.Orders.FirstOrDefault(x => x.Id == model.Id); + + if (order == null) + { + return null; + } + + order.Update(model); + source.SaveOrders(); + + return order.GetViewModel; + } } } -- 2.25.1 From 88555e8bdf32625ebee40da85742cec551da333b Mon Sep 17 00:00:00 2001 From: VictoriaPresnyakova Date: Mon, 20 Feb 2023 15:18:44 +0400 Subject: [PATCH 17/18] Jewel Storage full --- .../Implements/JewelStorage.cs | 72 ++++++++++++++++++- 1 file changed, 71 insertions(+), 1 deletion(-) diff --git a/JewelryStoreFileImplement/Implements/JewelStorage.cs b/JewelryStoreFileImplement/Implements/JewelStorage.cs index 2fb5632..5618d75 100644 --- a/JewelryStoreFileImplement/Implements/JewelStorage.cs +++ b/JewelryStoreFileImplement/Implements/JewelStorage.cs @@ -13,6 +13,76 @@ namespace JewelryStoreFileImplement.Implements { public class JewelStorage : IJewelStorage // TODO Lab_2 { - + private readonly DataFileSingleton _source; + public JewelStorage() + { + _source = DataFileSingleton.GetInstance(); + } + public List GetFullList() + { + return _source.Jewels.Select(x => x.GetViewModel).ToList(); + } + public List GetFilteredList(JewelSearchModel + model) + { + if (string.IsNullOrEmpty(model.JewelName)) + { + return new(); + } + return _source.Jewels + .Where(x => x.JewelName.Contains(model.JewelName)) + .Select(x => x.GetViewModel) + .ToList(); + + } + public JewelViewModel? GetElement(JewelSearchModel model) + { + if (string.IsNullOrEmpty(model.JewelName) && !model.Id.HasValue) + { + return null; + } + return _source.Jewels + .FirstOrDefault(x => + (!string.IsNullOrEmpty(model.JewelName) && x.JewelName == model.JewelName) || + (model.Id.HasValue && x.Id == model.Id))?.GetViewModel; + } + public JewelViewModel? Insert(JewelBindingModel model) + { + model.Id = _source.Jewels.Count > 0 ? _source.Jewels.Max(x => x.Id) + 1 : 1; + var newJewel = Jewel.Create(model); + if (newJewel == null) + { + return null; + } + _source.Jewels.Add(newJewel); + _source.SaveJewels(); + return newJewel.GetViewModel; + } + + public JewelViewModel? Update(JewelBindingModel model) + { + var component = _source.Jewels.FirstOrDefault(x => x.Id == model.Id); + if (component == null) + { + return null; + } + component.Update(model); + _source.SaveJewels(); + return component.GetViewModel; + + + } + public JewelViewModel? Delete(JewelBindingModel model) + { + var element = _source.Jewels.FirstOrDefault(x => x.Id == model.Id); + if (element != null) + { + _source.Jewels.Remove(element); + _source.SaveJewels(); + return element.GetViewModel; + } + return null; + + } } } -- 2.25.1 From 9d02e9815189e35db499c36e8a17152842069d23 Mon Sep 17 00:00:00 2001 From: VictoriaPresnyakova Date: Mon, 20 Feb 2023 15:26:09 +0400 Subject: [PATCH 18/18] full --- JewelryStore/JewelryStore.csproj | 5 +++++ JewelryStoreBusinessLogic/JewelryStoreBusinessLogic.csproj | 6 +++++- 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/JewelryStore/JewelryStore.csproj b/JewelryStore/JewelryStore.csproj index 1d74223..8a1c665 100644 --- a/JewelryStore/JewelryStore.csproj +++ b/JewelryStore/JewelryStore.csproj @@ -13,6 +13,11 @@ + + + + + diff --git a/JewelryStoreBusinessLogic/JewelryStoreBusinessLogic.csproj b/JewelryStoreBusinessLogic/JewelryStoreBusinessLogic.csproj index f21c000..d6db721 100644 --- a/JewelryStoreBusinessLogic/JewelryStoreBusinessLogic.csproj +++ b/JewelryStoreBusinessLogic/JewelryStoreBusinessLogic.csproj @@ -1,4 +1,4 @@ - + net6.0 @@ -10,6 +10,10 @@ + + + + -- 2.25.1