From 53192ffd12fd407caee5e5bc4800f7b320f85721 Mon Sep 17 00:00:00 2001 From: "ns.potapov" Date: Sun, 25 Feb 2024 22:08:12 +0400 Subject: [PATCH] =?UTF-8?q?=D0=A0=D0=B5=D0=B0=D0=BB=D0=B8=D0=B7=D0=BE?= =?UTF-8?q?=D0=B2=D0=B0=D0=BD=D1=8B=20=D0=B2=D1=81=D0=B5=20=D0=B1=D0=B8?= =?UTF-8?q?=D0=B1=D0=BB=D0=B8=D0=BE=D1=82=D0=B5=D0=BA=D0=B8=20=D0=BA=D0=BB?= =?UTF-8?q?=D0=B0=D1=81=D1=81=D0=BE=D0=B2=20=D0=B4=D0=BB=D1=8F=20=D0=BB?= =?UTF-8?q?=D0=B0=D0=B1.=20=D1=80=D0=B0=D0=B1=D0=BE=D1=82=D1=8B=201?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- SecuritySystem/SecuritySystem.sln | 6 + .../DataListSingleton.cs | 28 +++++ .../Implements/ComponentStorage.cs | 104 ++++++++++++++++ .../Implements/OrderStorage.cs | 115 ++++++++++++++++++ .../Implements/SecureStorage.cs | 108 ++++++++++++++++ .../Models/Component.cs | 41 +++++++ .../Models/Order.cs | 62 ++++++++++ .../Models/Secure.cs | 50 ++++++++ .../SecuritySystemListImplement.csproj | 14 +++ 9 files changed, 528 insertions(+) create mode 100644 SecuritySystem/SecuritySystemListImplement/DataListSingleton.cs create mode 100644 SecuritySystem/SecuritySystemListImplement/Implements/ComponentStorage.cs create mode 100644 SecuritySystem/SecuritySystemListImplement/Implements/OrderStorage.cs create mode 100644 SecuritySystem/SecuritySystemListImplement/Implements/SecureStorage.cs create mode 100644 SecuritySystem/SecuritySystemListImplement/Models/Component.cs create mode 100644 SecuritySystem/SecuritySystemListImplement/Models/Order.cs create mode 100644 SecuritySystem/SecuritySystemListImplement/Models/Secure.cs create mode 100644 SecuritySystem/SecuritySystemListImplement/SecuritySystemListImplement.csproj diff --git a/SecuritySystem/SecuritySystem.sln b/SecuritySystem/SecuritySystem.sln index 7a9ed1d..02b0a54 100644 --- a/SecuritySystem/SecuritySystem.sln +++ b/SecuritySystem/SecuritySystem.sln @@ -11,6 +11,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SecuritySystemContracts", " EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SecuritySystemBusinessLogic", "SecuritySystemBusinessLogic\SecuritySystemBusinessLogic.csproj", "{38C8A0AB-9363-4914-B967-02586827588D}" EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SecuritySystemListImplement", "SecuritySystemListImplement\SecuritySystemListImplement.csproj", "{6A104362-3398-4D4E-A3D0-2F4B32858569}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -33,6 +35,10 @@ Global {38C8A0AB-9363-4914-B967-02586827588D}.Debug|Any CPU.Build.0 = Debug|Any CPU {38C8A0AB-9363-4914-B967-02586827588D}.Release|Any CPU.ActiveCfg = Release|Any CPU {38C8A0AB-9363-4914-B967-02586827588D}.Release|Any CPU.Build.0 = Release|Any CPU + {6A104362-3398-4D4E-A3D0-2F4B32858569}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {6A104362-3398-4D4E-A3D0-2F4B32858569}.Debug|Any CPU.Build.0 = Debug|Any CPU + {6A104362-3398-4D4E-A3D0-2F4B32858569}.Release|Any CPU.ActiveCfg = Release|Any CPU + {6A104362-3398-4D4E-A3D0-2F4B32858569}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE diff --git a/SecuritySystem/SecuritySystemListImplement/DataListSingleton.cs b/SecuritySystem/SecuritySystemListImplement/DataListSingleton.cs new file mode 100644 index 0000000..0df80bb --- /dev/null +++ b/SecuritySystem/SecuritySystemListImplement/DataListSingleton.cs @@ -0,0 +1,28 @@ +using SecuritySystemListImplement.Models; + +namespace SecuritySystemListImplement +{ + public class DataListSingleton + { + private static DataListSingleton? _instance; + public List Components { get; set; } + public List Orders { get; set; } + public List Secures { get; set; } + private DataListSingleton() + { + Components = new List(); + Orders = new List(); + Secures = new List(); + } + public static DataListSingleton GetInstance() + { + if (_instance == null) + { + _instance = new DataListSingleton(); + } + return _instance; + } +22 + } + +} diff --git a/SecuritySystem/SecuritySystemListImplement/Implements/ComponentStorage.cs b/SecuritySystem/SecuritySystemListImplement/Implements/ComponentStorage.cs new file mode 100644 index 0000000..11a7c78 --- /dev/null +++ b/SecuritySystem/SecuritySystemListImplement/Implements/ComponentStorage.cs @@ -0,0 +1,104 @@ +using SecuritySystemContracts.BindingModels; +using SecuritySystemContracts.SearchModels; +using SecuritySystemContracts.StoragesContracts; +using SecuritySystemContracts.ViewModels; +using SecuritySystemListImplement.Models; + +namespace SecuritySystemListImplement.Implements +{ + public class ComponentStorage : IComponentStorage + { + private readonly DataListSingleton _source; + public ComponentStorage() + { + _source = DataListSingleton.GetInstance(); + } + public List GetFullList() + { + var result = new List(); + foreach (var component in _source.Components) + { + result.Add(component.GetViewModel); + } + return result; + } + public List GetFilteredList(ComponentSearchModel model) + { + var result = new List(); + if (string.IsNullOrEmpty(model.ComponentName)) + { + return result; + } + foreach (var component in _source.Components) + { + if (component.ComponentName.Contains(model.ComponentName)) + { + result.Add(component.GetViewModel); + } + } + return result; + } + public ComponentViewModel? GetElement(ComponentSearchModel model) + { + if (string.IsNullOrEmpty(model.ComponentName) && !model.Id.HasValue) + { + return null; + } + foreach (var component in _source.Components) + { + if ( + (!string.IsNullOrEmpty(model.ComponentName) && + component.ComponentName == model.ComponentName) || + (model.Id.HasValue && component.Id == model.Id) + ) + { + return component.GetViewModel; + } + } + return null; + } + public ComponentViewModel? Insert(ComponentBindingModel model) + { + model.Id = 1; + foreach (var component in _source.Components) + { + if (model.Id <= component.Id) + { + model.Id = component.Id + 1; + } + } + var newComponent = Component.Create(model); + if (newComponent == null) + { + return null; + } + _source.Components.Add(newComponent); + return newComponent.GetViewModel; + } + public ComponentViewModel? Update(ComponentBindingModel model) + { + foreach (var component in _source.Components) + { + if (component.Id == model.Id) + { + component.Update(model); + return component.GetViewModel; + } + } + return null; + } + public ComponentViewModel? Delete(ComponentBindingModel model) + { + for (int i = 0; i < _source.Components.Count; ++i) + { + if (_source.Components[i].Id == model.Id) + { + var element = _source.Components[i]; + _source.Components.RemoveAt(i); + return element.GetViewModel; + } + } + return null; + } + } +} diff --git a/SecuritySystem/SecuritySystemListImplement/Implements/OrderStorage.cs b/SecuritySystem/SecuritySystemListImplement/Implements/OrderStorage.cs new file mode 100644 index 0000000..3bc00f8 --- /dev/null +++ b/SecuritySystem/SecuritySystemListImplement/Implements/OrderStorage.cs @@ -0,0 +1,115 @@ +using SecuritySystemContracts.BindingModels; +using SecuritySystemContracts.SearchModels; +using SecuritySystemContracts.StoragesContracts; +using SecuritySystemContracts.ViewModels; +using SecuritySystemListImplement.Models; + +namespace SecuritySystemListImplement.Implements +{ + public class OrderStorage : IOrderStorage + { + private readonly DataListSingleton _source; + public OrderStorage() + { + _source = DataListSingleton.GetInstance(); + } + public List GetFullList() + { + var result = new List(); + foreach (var order in _source.Orders) + { + result.Add(GetViewModel(order)); + } + return result; + } + public List GetFilteredList(OrderSearchModel model) + { + var result = new List(); + if (!model.Id.HasValue) + { + return result; + } + foreach (var order in _source.Orders) + { + if (order.Id == model.Id) + { + result.Add(order.GetViewModel); + } + } + return result; + } + public OrderViewModel? GetElement(OrderSearchModel model) + { + if (!model.Id.HasValue) + { + return null; + } + foreach (var order in _source.Orders) + { + if ( + (model.Id.HasValue && order.Id == model.Id) + ) + { + return order.GetViewModel; + } + } + return null; + } + public OrderViewModel? Insert(OrderBindingModel model) + { + model.Id = 1; + foreach (var order in _source.Orders) + { + if (model.Id <= order.Id) + { + model.Id = order.Id + 1; + } + } + var newOrder = Order.Create(model); + if (newOrder == null) + { + return null; + } + _source.Orders.Add(newOrder); + return newOrder.GetViewModel; + } + public OrderViewModel? Update(OrderBindingModel model) + { + foreach (var order in _source.Orders) + { + if (order.Id == model.Id) + { + order.Update(model); + return order.GetViewModel; + } + } + return null; + } + public OrderViewModel? Delete(OrderBindingModel model) + { + for (int i = 0; i < _source.Orders.Count; ++i) + { + if (_source.Orders[i].Id == model.Id) + { + var element = _source.Orders[i]; + _source.Orders.RemoveAt(i); + return element.GetViewModel; + } + } + return null; + } + private OrderViewModel GetViewModel(Order order) + { + var viewModel = order.GetViewModel; + foreach (var secure in _source.Secures) + { + if (secure.Id == order.SecureId) + { + viewModel.SecureName = secure.SecureName; + break; + } + } + return viewModel; + } + } +} diff --git a/SecuritySystem/SecuritySystemListImplement/Implements/SecureStorage.cs b/SecuritySystem/SecuritySystemListImplement/Implements/SecureStorage.cs new file mode 100644 index 0000000..12b8535 --- /dev/null +++ b/SecuritySystem/SecuritySystemListImplement/Implements/SecureStorage.cs @@ -0,0 +1,108 @@ +using SecuritySystemContracts.BindingModels; +using SecuritySystemContracts.SearchModels; +using SecuritySystemContracts.StoragesContracts; +using SecuritySystemContracts.ViewModels; + +namespace SecuritySystemListImplement.Implements +{ + public class SecureStorage : ISecureStorage + { + private readonly DataListSingleton _source; + + public SecureStorage() + { + _source = DataListSingleton.GetInstance(); + } + + public List GetFullList() + { + var result = new List(); + foreach (var secure in _source.Secures) + { + result.Add(secure.GetViewModel); + } + return result; + } + + public List GetFilteredList(SecureSearchModel model) + { + var result = new List(); + if (string.IsNullOrEmpty(model.SecureName)) + { + return result; + } + foreach (var secure in _source.Secures) + { + if (secure.SecureName.Contains(model.SecureName)) + { + result.Add(secure.GetViewModel); + } + } + return result; + } + public SecureViewModel? GetElement(SecureSearchModel model) + { + if (string.IsNullOrEmpty(model.SecureName) && !model.Id.HasValue) + { + return null; + } + foreach (var secure in _source.Secures) + { + if ( + (!string.IsNullOrEmpty(model.SecureName) && + secure.SecureName == model.SecureName) || + (model.Id.HasValue && secure.Id == model.Id) + ) + { + return secure.GetViewModel; + } + } + return null; + } + + public SecureViewModel? Insert(SecureBindingModel model) + { + model.Id = 1; + foreach (var secure in _source.Secures) + { + if (model.Id <= secure.Id) + { + model.Id = secure.Id + 1; + } + } + var newSecure = Secure.Create(model); + if (newSecure == null) + { + return null; + } + _source.Secures.Add(newSecure); + return newSecure.GetViewModel; + } + + public SecureViewModel? Update(SecureBindingModel model) + { + foreach (var secure in _source.Secures) + { + if (secure.Id == model.Id) + { + secure.Update(model); + return secure.GetViewModel; + } + } + return null; + } + public SecureViewModel? Delete(SecureBindingModel model) + { + for (int i = 0; i < _source.Secures.Count; ++i) + { + if (_source.Secures[i].Id == model.Id) + { + var element = _source.Secures[i]; + _source.Secures.RemoveAt(i); + return element.GetViewModel; + } + } + return null; + } + } +} diff --git a/SecuritySystem/SecuritySystemListImplement/Models/Component.cs b/SecuritySystem/SecuritySystemListImplement/Models/Component.cs new file mode 100644 index 0000000..804f338 --- /dev/null +++ b/SecuritySystem/SecuritySystemListImplement/Models/Component.cs @@ -0,0 +1,41 @@ +using SecuritySystemContracts.BindingModels; +using SecuritySystemContracts.ViewModels; +using SecuritySystemDataModels.Models; + +namespace SecuritySystemListImplement.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 void Update(ComponentBindingModel? model) + { + if (model == null) + { + return; + } + ComponentName = model.ComponentName; + Cost = model.Cost; + } + public ComponentViewModel GetViewModel => new() + { + Id = Id, + ComponentName = ComponentName, + Cost = Cost + }; + } +} diff --git a/SecuritySystem/SecuritySystemListImplement/Models/Order.cs b/SecuritySystem/SecuritySystemListImplement/Models/Order.cs new file mode 100644 index 0000000..47bc31d --- /dev/null +++ b/SecuritySystem/SecuritySystemListImplement/Models/Order.cs @@ -0,0 +1,62 @@ +using SecuritySystemContracts.BindingModels; +using SecuritySystemContracts.ViewModels; +using SecuritySystemDataModels.Enums; + +namespace SecuritySystemListImplement.Models +{ + public class Order + { + public int SecureId { get; private set; } + + 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, + SecureId = model.SecureId, + Count = model.Count, + Sum = model.Sum, + Status = model.Status, + DateCreate = model.DateCreate, + DateImplement = model.DateImplement, + }; + } + + public void Update(OrderBindingModel? model) + { + if (model == null) + { + return; + } + Status = model.Status; + DateImplement = model.DateImplement; + } + + public OrderViewModel GetViewModel => new() + { + SecureId = SecureId, + Count = Count, + Sum = Sum, + DateCreate = DateCreate, + DateImplement = DateImplement, + Id = Id, + Status = Status, + }; + } +} diff --git a/SecuritySystem/SecuritySystemListImplement/Models/Secure.cs b/SecuritySystem/SecuritySystemListImplement/Models/Secure.cs new file mode 100644 index 0000000..9b5698a --- /dev/null +++ b/SecuritySystem/SecuritySystemListImplement/Models/Secure.cs @@ -0,0 +1,50 @@ +using SecuritySystemContracts.BindingModels; +using SecuritySystemContracts.ViewModels; +using SecuritySystemDataModels.Models; + +namespace SecuritySystemListImplement.Models +{ + public class Secure : ISecureModel + { + public int Id { get; private set; } + public string SecureName { get; private set; } = string.Empty; + public double Price { get; private set; } + public Dictionary SecureComponents + { + get; + private set; + } = new Dictionary(); + public static Secure? Create(SecureBindingModel? model) + { + if (model == null) + { + return null; + } + return new Secure() + { + Id = model.Id, + SecureName = model.SecureName, + Price = model.Price, + SecureComponents = model.SecureComponents + }; + } + public void Update(SecureBindingModel? model) + { + if (model == null) + { + return; + } + SecureName = model.SecureName; + Price = model.Price; + SecureComponents = model.SecureComponents; + } + public SecureViewModel GetViewModel => new() + { + Id = Id, + SecureName = SecureName, + Price = Price, + SecureComponents = SecureComponents + }; + + } +} diff --git a/SecuritySystem/SecuritySystemListImplement/SecuritySystemListImplement.csproj b/SecuritySystem/SecuritySystemListImplement/SecuritySystemListImplement.csproj new file mode 100644 index 0000000..7d1c090 --- /dev/null +++ b/SecuritySystem/SecuritySystemListImplement/SecuritySystemListImplement.csproj @@ -0,0 +1,14 @@ + + + + net6.0 + enable + enable + + + + + + + +