From 2be99ee0214c5733902d083f407ed707a4f08748 Mon Sep 17 00:00:00 2001 From: malimova Date: Fri, 16 Feb 2024 00:08:59 +0400 Subject: [PATCH] =?UTF-8?q?=D0=9A=D0=BB=D0=B0=D1=81=D1=81=D1=8B=20=D0=B4?= =?UTF-8?q?=D0=BB=D1=8F=20ConfectioneryListImplement?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Confectionery/Confectionery.sln | 6 + .../ConfectioneryListImplement/Component.cs | 46 +++++++ .../ComponentStorage.cs | 108 +++++++++++++++ .../ConfectioneryListImplement.csproj | 14 ++ .../DataListSingleton.cs | 31 +++++ .../ConfectioneryListImplement/Order.cs | 62 +++++++++ .../OrderStorage.cs | 125 ++++++++++++++++++ .../ConfectioneryListImplement/Pastry.cs | 50 +++++++ .../PastryStorage.cs | 113 ++++++++++++++++ 9 files changed, 555 insertions(+) create mode 100644 Confectionery/ConfectioneryListImplement/Component.cs create mode 100644 Confectionery/ConfectioneryListImplement/ComponentStorage.cs create mode 100644 Confectionery/ConfectioneryListImplement/ConfectioneryListImplement.csproj create mode 100644 Confectionery/ConfectioneryListImplement/DataListSingleton.cs create mode 100644 Confectionery/ConfectioneryListImplement/Order.cs create mode 100644 Confectionery/ConfectioneryListImplement/OrderStorage.cs create mode 100644 Confectionery/ConfectioneryListImplement/Pastry.cs create mode 100644 Confectionery/ConfectioneryListImplement/PastryStorage.cs diff --git a/Confectionery/Confectionery.sln b/Confectionery/Confectionery.sln index 1097f78..0290134 100644 --- a/Confectionery/Confectionery.sln +++ b/Confectionery/Confectionery.sln @@ -11,6 +11,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ConfectioneryContracts", "C EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ConfectioneryBusinessLogic", "ConfectioneryBusinessLogic\ConfectioneryBusinessLogic.csproj", "{A8B0F9F7-FBAA-41C1-A211-DAA3685C9F4E}" EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ConfectioneryListImplement", "ConfectioneryListImplement\ConfectioneryListImplement.csproj", "{BE302C97-48E7-4982-8D16-309157B55944}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -33,6 +35,10 @@ Global {A8B0F9F7-FBAA-41C1-A211-DAA3685C9F4E}.Debug|Any CPU.Build.0 = Debug|Any CPU {A8B0F9F7-FBAA-41C1-A211-DAA3685C9F4E}.Release|Any CPU.ActiveCfg = Release|Any CPU {A8B0F9F7-FBAA-41C1-A211-DAA3685C9F4E}.Release|Any CPU.Build.0 = Release|Any CPU + {BE302C97-48E7-4982-8D16-309157B55944}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {BE302C97-48E7-4982-8D16-309157B55944}.Debug|Any CPU.Build.0 = Debug|Any CPU + {BE302C97-48E7-4982-8D16-309157B55944}.Release|Any CPU.ActiveCfg = Release|Any CPU + {BE302C97-48E7-4982-8D16-309157B55944}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE diff --git a/Confectionery/ConfectioneryListImplement/Component.cs b/Confectionery/ConfectioneryListImplement/Component.cs new file mode 100644 index 0000000..1021c14 --- /dev/null +++ b/Confectionery/ConfectioneryListImplement/Component.cs @@ -0,0 +1,46 @@ +using ConfectioneryContracts.BindingModels; +using ConfectioneryContracts.ViewModels; +using ConfectioneryDataModels.Models; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace ConfectioneryListImplement.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/Confectionery/ConfectioneryListImplement/ComponentStorage.cs b/Confectionery/ConfectioneryListImplement/ComponentStorage.cs new file mode 100644 index 0000000..9a87ea0 --- /dev/null +++ b/Confectionery/ConfectioneryListImplement/ComponentStorage.cs @@ -0,0 +1,108 @@ +using ConfectioneryContracts.BindingModels; +using ConfectioneryContracts.SearchModels; +using ConfectioneryContracts.StoragesContracts; +using ConfectioneryContracts.ViewModels; +using ConfectioneryListImplement.Models; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace ConfectioneryListImplement.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/Confectionery/ConfectioneryListImplement/ConfectioneryListImplement.csproj b/Confectionery/ConfectioneryListImplement/ConfectioneryListImplement.csproj new file mode 100644 index 0000000..41b6c3e --- /dev/null +++ b/Confectionery/ConfectioneryListImplement/ConfectioneryListImplement.csproj @@ -0,0 +1,14 @@ + + + + net6.0 + enable + enable + + + + + + + + diff --git a/Confectionery/ConfectioneryListImplement/DataListSingleton.cs b/Confectionery/ConfectioneryListImplement/DataListSingleton.cs new file mode 100644 index 0000000..37eca03 --- /dev/null +++ b/Confectionery/ConfectioneryListImplement/DataListSingleton.cs @@ -0,0 +1,31 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using ConfectioneryListImplement.Models; + +namespace ConfectioneryListImplement +{ + public class DataListSingleton + { + private static DataListSingleton? _instance; + public List Components { get; set; } + public List Orders { get; set; } + public List Pastrys { get; set; } + private DataListSingleton() + { + Components = new List(); + Orders = new List(); + Pastrys = new List(); + } + public static DataListSingleton GetInstance() + { + if (_instance == null) + { + _instance = new DataListSingleton(); + } + return _instance; + } + } +} diff --git a/Confectionery/ConfectioneryListImplement/Order.cs b/Confectionery/ConfectioneryListImplement/Order.cs new file mode 100644 index 0000000..6076de8 --- /dev/null +++ b/Confectionery/ConfectioneryListImplement/Order.cs @@ -0,0 +1,62 @@ +using ConfectioneryContracts.BindingModels; +using ConfectioneryContracts.ViewModels; +using ConfectioneryDataModels.Enums; +using ConfectioneryDataModels.Models; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace ConfectioneryListImplement.Models +{ + public class Order : IOrderModel + { + public int Id { get; private set; } + public int PastryId { 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 static Order? Create(OrderBindingModel? model) + { + if (model == null) + { + return null; + } + return new Order() + { + Id = model.Id, + PastryId = model.PastryId, + 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; + if (model.Status == OrderStatus.Выдан) DateImplement = model.DateImplement; + } + + public OrderViewModel GetViewModel => new() + { + Id = Id, + PastryId = PastryId, + Count = Count, + Sum = Sum, + Status = Status, + DateCreate = DateCreate, + DateImplement = DateImplement, + }; + } +} diff --git a/Confectionery/ConfectioneryListImplement/OrderStorage.cs b/Confectionery/ConfectioneryListImplement/OrderStorage.cs new file mode 100644 index 0000000..0cc40fd --- /dev/null +++ b/Confectionery/ConfectioneryListImplement/OrderStorage.cs @@ -0,0 +1,125 @@ +using ConfectioneryContracts.BindingModels; +using ConfectioneryContracts.SearchModels; +using ConfectioneryContracts.StoragesContracts; +using ConfectioneryContracts.ViewModels; +using ConfectioneryListImplement.Models; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace ConfectioneryListImplement +{ + 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(AttachPastryName(order.GetViewModel)); + } + return result; + } + + public List GetFilteredList(OrderSearchModel model) + { + var result = new List(); + if (model == null || !model.Id.HasValue) + { + return result; + } + foreach (var order in _source.Orders) + { + if (order.Id == model.Id) + { + result.Add(AttachPastryName(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 AttachPastryName(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 AttachPastryName(newOrder.GetViewModel); + } + + public OrderViewModel? Update(OrderBindingModel model) + { + foreach (var order in _source.Orders) + { + if (order.Id == model.Id) + { + order.Update(model); + return AttachPastryName(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 AttachPastryName(element.GetViewModel); + } + } + return null; + } + + private OrderViewModel AttachPastryName(OrderViewModel model) + { + foreach (var Pastry in _source.Pastrys) + { + if (Pastry.Id == model.PastryId) + { + model.PastryName = Pastry.PastryName; + return model; + } + } + return model; + } + } +} diff --git a/Confectionery/ConfectioneryListImplement/Pastry.cs b/Confectionery/ConfectioneryListImplement/Pastry.cs new file mode 100644 index 0000000..e303630 --- /dev/null +++ b/Confectionery/ConfectioneryListImplement/Pastry.cs @@ -0,0 +1,50 @@ +using ConfectioneryContracts.BindingModels; +using ConfectioneryContracts.ViewModels; +using ConfectioneryDataModels.Models; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace ConfectioneryListImplement.Models +{ + public class Pastry : IPastryModel + { + public int Id { get; private set; } + public string PastryName { get; private set; } = string.Empty; + public double Price { get; private set; } + public Dictionary PastryComponents { get; private set; } = new Dictionary(); + public static Pastry? Create(PastryBindingModel? model) + { + if (model == null) + { + return null; + } + return new Pastry() + { + Id = model.Id, + PastryName = model.PastryName, + Price = model.Price, + PastryComponents = model.PastryComponents + }; + } + public void Update(PastryBindingModel? model) + { + if (model == null) + { + return; + } + PastryName = model.PastryName; + Price = model.Price; + PastryComponents = model.PastryComponents; + } + public PastryViewModel GetViewModel => new() + { + Id = Id, + PastryName = PastryName, + Price = Price, + PastryComponents = PastryComponents + }; + } +} diff --git a/Confectionery/ConfectioneryListImplement/PastryStorage.cs b/Confectionery/ConfectioneryListImplement/PastryStorage.cs new file mode 100644 index 0000000..2ec58c0 --- /dev/null +++ b/Confectionery/ConfectioneryListImplement/PastryStorage.cs @@ -0,0 +1,113 @@ +using ConfectioneryContracts.BindingModels; +using ConfectioneryContracts.SearchModels; +using ConfectioneryContracts.StoragesContracts; +using ConfectioneryContracts.ViewModels; +using ConfectioneryListImplement.Models; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace ConfectioneryListImplement +{ + public class PastryStorage : IPastryStorage + { + private readonly DataListSingleton _source; + + public PastryStorage() + { + _source = DataListSingleton.GetInstance(); + } + + public List GetFullList() + { + var result = new List(); + foreach (var Pastrys in _source.Pastrys) + { + result.Add(Pastrys.GetViewModel); + } + return result; + } + + public List GetFilteredList(PastrySearchModel model) + { + var result = new List(); + if (string.IsNullOrEmpty(model.PastryName)) + { + return result; + } + foreach (var Pastrys in _source.Pastrys) + { + if (Pastrys.PastryName.Contains(model.PastryName)) + { + result.Add(Pastrys.GetViewModel); + } + } + return result; + } + + public PastryViewModel? GetElement(PastrySearchModel model) + { + if (string.IsNullOrEmpty(model.PastryName) && !model.Id.HasValue) + { + return null; + } + foreach (var Pastrys in _source.Pastrys) + { + if ((!string.IsNullOrEmpty(model.PastryName) && Pastrys.PastryName == model.PastryName) || + (model.Id.HasValue && Pastrys.Id == model.Id)) + { + return Pastrys.GetViewModel; + } + } + return null; + } + + public PastryViewModel? Insert(PastryBindingModel model) + { + model.Id = 1; + foreach (var Pastrys in _source.Pastrys) + { + if (model.Id <= Pastrys.Id) + { + model.Id = Pastrys.Id + 1; + } + } + var newPastrys = Pastry.Create(model); + if (newPastrys == null) + { + return null; + } + _source.Pastrys.Add(newPastrys); + return newPastrys.GetViewModel; + } + + public PastryViewModel? Update(PastryBindingModel model) + { + foreach (var Pastrys in _source.Pastrys) + { + if (Pastrys.Id == model.Id) + { + Pastrys.Update(model); + return Pastrys.GetViewModel; + } + } + return null; + } + + public PastryViewModel? Delete(PastryBindingModel model) + { + for (int i = 0; i < _source.Pastrys.Count; ++i) + { + if (_source.Pastrys[i].Id == model.Id) + { + var element = _source.Pastrys[i]; + _source.Pastrys.RemoveAt(i); + return element.GetViewModel; + } + } + return null; + } + } +}