From cfb587fb59fa6e1662cde93cc1c31a2b19d71046 Mon Sep 17 00:00:00 2001 From: "ns.potapov" Date: Sun, 7 Apr 2024 20:45:51 +0400 Subject: [PATCH] =?UTF-8?q?=D0=94=D0=BE=D0=B1=D0=B0=D0=B2=D0=BB=D0=B5?= =?UTF-8?q?=D0=BD=D0=B0=20=D0=BC=D0=BE=D0=B4=D0=B5=D0=BB=D1=8C=20=D0=BC?= =?UTF-8?q?=D0=B0=D0=B3=D0=B0=D0=B7=D0=B8=D0=BD=D0=B0=20=D0=B2=20=D1=80?= =?UTF-8?q?=D0=B5=D0=B0=D0=BB=D0=B8=D0=B7=D0=B0=D1=86=D0=B8=D1=8E=20=D1=85?= =?UTF-8?q?=D1=80=D0=B0=D0=BD=D0=B8=D0=BB=D0=B8=D1=89=D0=B0=20=D0=BD=D0=B0?= =?UTF-8?q?=20=D1=81=D0=BF=D0=B8=D1=81=D0=BA=D0=B0=D1=85.=20=D0=94=D0=BE?= =?UTF-8?q?=D0=B1=D0=B0=D0=B2=D0=BB=D0=B5=D0=BD=D0=BE=20=D0=BF=D0=BE=D0=BB?= =?UTF-8?q?=D0=B5=20=D0=BC=D0=B0=D0=BA=D1=81=D0=B8=D0=BC=D0=B0=D0=BB=D1=8C?= =?UTF-8?q?=D0=BD=D0=BE=D0=B3=D0=BE=20=D0=BA=D0=BE=D0=BB-=D0=B2=D0=B0=20?= =?UTF-8?q?=D1=82=D0=BE=D0=B2=D0=B0=D1=80=D0=B0.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../BindingModels/ShopBindingModel.cs | 5 +- .../ViewModels/ShopViewModel.cs | 2 + .../Models/IShopModel.cs | 1 + .../Models/Shop.cs | 111 ++++++++++++++++++ .../Models/Shop.cs | 5 +- 5 files changed, 119 insertions(+), 5 deletions(-) create mode 100644 SecuritySystem/SecuritySystemFileImplement/Models/Shop.cs diff --git a/SecuritySystem/SecuritySystemContracts/BindingModels/ShopBindingModel.cs b/SecuritySystem/SecuritySystemContracts/BindingModels/ShopBindingModel.cs index caeb197..c1d683a 100644 --- a/SecuritySystem/SecuritySystemContracts/BindingModels/ShopBindingModel.cs +++ b/SecuritySystem/SecuritySystemContracts/BindingModels/ShopBindingModel.cs @@ -5,13 +5,10 @@ namespace SecuritySystemContracts.BindingModels public class ShopBindingModel : IShopModel { public int Id { get; set; } - public string Name { get; set; } = string.Empty; - public string Address { get; set; } = string.Empty; - public DateTime OpeningDate { get; set; } - + public int MaxSecuresCount { get; set; } public Dictionary ShopSecures { get; set; } = new(); } } diff --git a/SecuritySystem/SecuritySystemContracts/ViewModels/ShopViewModel.cs b/SecuritySystem/SecuritySystemContracts/ViewModels/ShopViewModel.cs index d6923fc..e8bc4ca 100644 --- a/SecuritySystem/SecuritySystemContracts/ViewModels/ShopViewModel.cs +++ b/SecuritySystem/SecuritySystemContracts/ViewModels/ShopViewModel.cs @@ -10,6 +10,8 @@ namespace SecuritySystemContracts.ViewModels public string Name { get; set; } = string.Empty; [DisplayName("Адрес")] public string Address { get; set; } = string.Empty; + [DisplayName("Макс. кол-во товара")] + public int MaxSecuresCount { get; set; } [DisplayName("Дата открытия")] public DateTime OpeningDate { get; set; } public Dictionary ShopSecures { get; set; } = new(); diff --git a/SecuritySystem/SecuritySystemDataModels/Models/IShopModel.cs b/SecuritySystem/SecuritySystemDataModels/Models/IShopModel.cs index da3eecc..91bea8c 100644 --- a/SecuritySystem/SecuritySystemDataModels/Models/IShopModel.cs +++ b/SecuritySystem/SecuritySystemDataModels/Models/IShopModel.cs @@ -5,6 +5,7 @@ string Name { get; } string Address { get; } DateTime OpeningDate { get; } + int MaxSecuresCount { get; } Dictionary ShopSecures { get; } } } diff --git a/SecuritySystem/SecuritySystemFileImplement/Models/Shop.cs b/SecuritySystem/SecuritySystemFileImplement/Models/Shop.cs new file mode 100644 index 0000000..74a2363 --- /dev/null +++ b/SecuritySystem/SecuritySystemFileImplement/Models/Shop.cs @@ -0,0 +1,111 @@ +using SecuritySystemContracts.BindingModels; +using SecuritySystemContracts.ViewModels; +using SecuritySystemDataModels.Models; +using SecuritySystemFileImplement; +using System.Xml.Linq; + +namespace AutomobilePlantFileImplement.Models +{ + public class Shop : IShopModel + { + public int Id { get; private set; } + public string Name { get; private set; } = string.Empty; + public string Address { get; private set; } = string.Empty; + public int MaxSecuresCount { get; private set; } + public DateTime OpeningDate { get; private set; } + public Dictionary Secures { get; private set; } = new(); + private Dictionary? _shopSecures = null; + public Dictionary ShopSecures + { + get + { + if (_shopSecures == null) + { + var source = DataFileSingleton.GetInstance(); + _shopSecures = Secures.ToDictionary( + x => x.Key, + y => ((source.Secures.FirstOrDefault(z => z.Id == y.Key) as ISecureModel)!, y.Value) + ); + } + return _shopSecures; + } + } + + public static Shop? Create(ShopBindingModel? model) + { + if (model == null) + { + return null; + } + return new Shop() + { + Id = model.Id, + Name = model.Name, + Address = model.Address, + MaxSecuresCount = model.MaxSecuresCount, + OpeningDate = model.OpeningDate, + Secures = model.ShopSecures.ToDictionary(x => x.Key, x => x.Value.Item2) + }; + } + + public static Shop? Create(XElement element) + { + if (element == null) + { + return null; + } + return new Shop() + { + Id = Convert.ToInt32(element.Attribute("Id")!.Value), + Name = element.Element("Name")!.Value, + Address = element.Element("Address")!.Value, + MaxSecuresCount = Convert.ToInt32(element.Element("MaxSecuresCount")!.Value), + OpeningDate = Convert.ToDateTime(element.Element("OpeningDate")!.Value), + Secures = element.Element("ShopSecures")!.Elements("ShopSecure").ToDictionary( + x => Convert.ToInt32(x.Element("Key")?.Value), + x => Convert.ToInt32(x.Element("Value")?.Value) + ) + }; + } + + + public void Update(ShopBindingModel? model) + { + if (model == null) + { + return; + } + Name = model.Name; + Address = model.Address; + MaxSecuresCount = model.MaxSecuresCount; + OpeningDate = model.OpeningDate; + if (model.ShopSecures.Count > 0) + { + Secures = model.ShopSecures.ToDictionary(x => x.Key, x => x.Value.Item2); + _shopSecures = null; + } + } + public ShopViewModel GetViewModel => new() + { + Id = Id, + Name = Name, + Address = Address, + MaxSecuresCount = MaxSecuresCount, + OpeningDate = OpeningDate, + ShopSecures = ShopSecures, + }; + + public XElement GetXElement => new( + "Shop", + new XAttribute("Id", Id), + new XElement("Name", Name), + new XElement("Address", Address), + new XElement("MaxSecuresCount", MaxSecuresCount), + new XElement("OpeningDate", OpeningDate.ToString()), + new XElement("ShopSecures", Secures.Select(x => + new XElement("ShopSecure", + new XElement("Key", x.Key), + new XElement("Value", x.Value))) + .ToArray())); + } +} diff --git a/SecuritySystem/SecuritySystemListImplement/Models/Shop.cs b/SecuritySystem/SecuritySystemListImplement/Models/Shop.cs index dd5e4a5..6b4621d 100644 --- a/SecuritySystem/SecuritySystemListImplement/Models/Shop.cs +++ b/SecuritySystem/SecuritySystemListImplement/Models/Shop.cs @@ -10,8 +10,8 @@ namespace SecuritySystemListImplement.Models public string Name { get; private set; } = string.Empty; public string Address { get; private set; } = string.Empty; public DateTime OpeningDate { get; private set; } + public int MaxSecuresCount { get; private set; } public Dictionary ShopSecures { get; private set; } = new(); - public static Shop? Create(ShopBindingModel model) { if (model == null) @@ -25,6 +25,7 @@ namespace SecuritySystemListImplement.Models Name = model.Name, Address = model.Address, OpeningDate = model.OpeningDate, + MaxSecuresCount = model.MaxSecuresCount, ShopSecures = new() }; } @@ -39,6 +40,7 @@ namespace SecuritySystemListImplement.Models Name = model.Name; Address = model.Address; OpeningDate = model.OpeningDate; + MaxSecuresCount = model.MaxSecuresCount; ShopSecures = model.ShopSecures; } @@ -48,6 +50,7 @@ namespace SecuritySystemListImplement.Models Name = Name, Address = Address, OpeningDate = OpeningDate, + MaxSecuresCount = MaxSecuresCount, ShopSecures = ShopSecures }; }