From 0a8fd1126d97b72cafa2fe6ee18abf1a25c56d7a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=9C=D0=B0=D0=BA=D1=81=D0=B8=D0=BC=20=D0=AF=D0=BA=D0=BE?= =?UTF-8?q?=D0=B2=D0=BB=D0=B5=D0=B2?= Date: Tue, 26 Mar 2024 20:35:34 +0400 Subject: [PATCH] =?UTF-8?q?=D0=A1=D0=BB=D0=BE=D0=B9=20=D0=B1=D0=B8=D0=B7?= =?UTF-8?q?=D0=BD=D0=B5=D1=81=20=D0=BB=D0=BE=D0=B3=D0=B8=D0=BA=D0=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- SushiBar/SushiBar.sln | 6 ++ .../BusinessLogics/BuyerLogic.cs | 94 +++++++++++++++++++ .../BusinessLogics/CookLogic.cs | 93 ++++++++++++++++++ .../BusinessLogics/MenuLogic.cs | 93 ++++++++++++++++++ .../BusinessLogics/PlaceLogic.cs | 93 ++++++++++++++++++ .../BusinessLogics/TaskLogic.cs | 89 ++++++++++++++++++ .../SushiBarBusinessLogic.csproj | 14 +++ .../StoragesContracts/IBuyerStorage.cs | 9 +- .../StoragesContracts/ICookStorage.cs | 9 +- .../StoragesContracts/IMenuStorage.cs | 9 +- .../StoragesContracts/IPlaceStorage.cs | 9 +- .../StoragesContracts/ITaskStorage.cs | 9 +- 12 files changed, 507 insertions(+), 20 deletions(-) create mode 100644 SushiBar/SushiBarBusinessLogic/BusinessLogics/BuyerLogic.cs create mode 100644 SushiBar/SushiBarBusinessLogic/BusinessLogics/CookLogic.cs create mode 100644 SushiBar/SushiBarBusinessLogic/BusinessLogics/MenuLogic.cs create mode 100644 SushiBar/SushiBarBusinessLogic/BusinessLogics/PlaceLogic.cs create mode 100644 SushiBar/SushiBarBusinessLogic/BusinessLogics/TaskLogic.cs create mode 100644 SushiBar/SushiBarBusinessLogic/SushiBarBusinessLogic.csproj diff --git a/SushiBar/SushiBar.sln b/SushiBar/SushiBar.sln index e05cd60..7bbcf92 100644 --- a/SushiBar/SushiBar.sln +++ b/SushiBar/SushiBar.sln @@ -9,6 +9,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SushiBarDataModels", "Sushi EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SushiBarContracts", "SushiBarContracts\SushiBarContracts.csproj", "{1FD289B3-1422-4535-8969-2F320754517B}" EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SushiBarBusinessLogic", "SushiBarBusinessLogic\SushiBarBusinessLogic.csproj", "{9CB0FFA6-FA25-440C-8B6A-B6DF2F0639F5}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -27,6 +29,10 @@ Global {1FD289B3-1422-4535-8969-2F320754517B}.Debug|Any CPU.Build.0 = Debug|Any CPU {1FD289B3-1422-4535-8969-2F320754517B}.Release|Any CPU.ActiveCfg = Release|Any CPU {1FD289B3-1422-4535-8969-2F320754517B}.Release|Any CPU.Build.0 = Release|Any CPU + {9CB0FFA6-FA25-440C-8B6A-B6DF2F0639F5}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {9CB0FFA6-FA25-440C-8B6A-B6DF2F0639F5}.Debug|Any CPU.Build.0 = Debug|Any CPU + {9CB0FFA6-FA25-440C-8B6A-B6DF2F0639F5}.Release|Any CPU.ActiveCfg = Release|Any CPU + {9CB0FFA6-FA25-440C-8B6A-B6DF2F0639F5}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE diff --git a/SushiBar/SushiBarBusinessLogic/BusinessLogics/BuyerLogic.cs b/SushiBar/SushiBarBusinessLogic/BusinessLogics/BuyerLogic.cs new file mode 100644 index 0000000..d130dd4 --- /dev/null +++ b/SushiBar/SushiBarBusinessLogic/BusinessLogics/BuyerLogic.cs @@ -0,0 +1,94 @@ +using SushiBarContracts.BindingModels; +using SushiBarContracts.BusinessLogicContracts; +using SushiBarContracts.SearchModels; +using SushiBarContracts.StoragesContracts; +using SushiBarContracts.ViewModels; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace SushiBarBusinessLogic.BusinessLogics +{ + public class BuyerLogic : IBuyerLogic + { + + private readonly IBuyerStorage _buyerStorage; + + public BuyerLogic(IBuyerStorage buyerStorage) + { + _buyerStorage = buyerStorage; + } + public BuyerViewModel? ReadElement(BuyerSearchModel model) + { + if (model == null) + { + throw new ArgumentNullException(nameof(model)); + } + + var element = _buyerStorage.GetElement(model); + if(element == null) + { + return null; + } + return element; + } + + public List? ReadList(BuyerSearchModel? model) + { + var list = model == null ? _buyerStorage.GetFullList() : _buyerStorage.GetFilteredList(model); + if(list == null) + { + return null; + } + return list; + } + + public bool Create(BuyerBindingModel model) + { + CheckModel(model); + if (_buyerStorage.Insert(model) == null) + { + return false; + } + return true; + } + + public bool Delete(BuyerBindingModel model) + { + CheckModel(model, false); + if(_buyerStorage.Delete(model) == null) + { + return false; + } + return true; + } + + public bool Update(BuyerBindingModel model) + { + CheckModel(model); + if(_buyerStorage.Update(model) == null) + { + return false; + } + return true; + } + + private void CheckModel(BuyerBindingModel model, bool withParams = true) + { + if (model == null) + { + throw new ArgumentNullException(nameof(model)); + } + if (!withParams) + { + return; + } + if (string.IsNullOrEmpty(model.BuyerName)) + { + throw new ArgumentNullException("Нет названия", nameof(model.BuyerName)); + } + } + } +} diff --git a/SushiBar/SushiBarBusinessLogic/BusinessLogics/CookLogic.cs b/SushiBar/SushiBarBusinessLogic/BusinessLogics/CookLogic.cs new file mode 100644 index 0000000..7bfa486 --- /dev/null +++ b/SushiBar/SushiBarBusinessLogic/BusinessLogics/CookLogic.cs @@ -0,0 +1,93 @@ +using SushiBarContracts.BindingModels; +using SushiBarContracts.BusinessLogicContracts; +using SushiBarContracts.SearchModels; +using SushiBarContracts.StoragesContracts; +using SushiBarContracts.ViewModels; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace SushiBarBusinessLogic.BusinessLogics +{ + public class CookLogic : ICookLogic + { + private readonly ICookStorage _cookStorage; + + public CookLogic(ICookStorage cookStorage) + { + _cookStorage = cookStorage; + } + public CookViewModel? ReadElement(CookSearchModel model) + { + if (model == null) + { + throw new ArgumentNullException(nameof(model)); + } + + var element = _cookStorage.GetElement(model); + if (element == null) + { + return null; + } + return element; + } + + public List? ReadList(CookSearchModel? model) + { + var list = model == null ? _cookStorage.GetFullList() : _cookStorage.GetFilteredList(model); + if (list == null) + { + return null; + } + return list; + } + + public bool Create(CookBindingModel model) + { + CheckModel(model); + if (_cookStorage.Insert(model) == null) + { + return false; + } + return true; + } + + public bool Delete(CookBindingModel model) + { + CheckModel(model, false); + if (_cookStorage.Delete(model) == null) + { + return false; + } + return true; + } + + public bool Update(CookBindingModel model) + { + CheckModel(model); + if (_cookStorage.Update(model) == null) + { + return false; + } + return true; + } + + private void CheckModel(CookBindingModel model, bool withParams = true) + { + if (model == null) + { + throw new ArgumentNullException(nameof(model)); + } + if (!withParams) + { + return; + } + if (string.IsNullOrEmpty(model.CookName)) + { + throw new ArgumentNullException("Нет названия", nameof(model.CookName)); + } + } + } +} diff --git a/SushiBar/SushiBarBusinessLogic/BusinessLogics/MenuLogic.cs b/SushiBar/SushiBarBusinessLogic/BusinessLogics/MenuLogic.cs new file mode 100644 index 0000000..380ceee --- /dev/null +++ b/SushiBar/SushiBarBusinessLogic/BusinessLogics/MenuLogic.cs @@ -0,0 +1,93 @@ +using SushiBarContracts.BindingModels; +using SushiBarContracts.BusinessLogicContracts; +using SushiBarContracts.SearchModels; +using SushiBarContracts.StoragesContracts; +using SushiBarContracts.ViewModels; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace SushiBarBusinessLogic.BusinessLogics +{ + public class MenuLogic : IMenuLogic + { + private readonly IMenuStorage _menuStorage; + + public MenuLogic(IMenuStorage menuStorage) + { + _menuStorage = menuStorage; + } + public MenuViewModel? ReadElement(MenuSearchModel model) + { + if (model == null) + { + throw new ArgumentNullException(nameof(model)); + } + + var element = _menuStorage.GetElement(model); + if (element == null) + { + return null; + } + return element; + } + + public List? ReadList(MenuSearchModel? model) + { + var list = model == null ? _menuStorage.GetFullList() : _menuStorage.GetFilteredList(model); + if (list == null) + { + return null; + } + return list; + } + + public bool Create(MenuBindingModel model) + { + CheckModel(model); + if (_menuStorage.Insert(model) == null) + { + return false; + } + return true; + } + + public bool Delete(MenuBindingModel model) + { + CheckModel(model, false); + if (_menuStorage.Delete(model) == null) + { + return false; + } + return true; + } + + public bool Update(MenuBindingModel model) + { + CheckModel(model); + if (_menuStorage.Update(model) == null) + { + return false; + } + return true; + } + + private void CheckModel(MenuBindingModel model, bool withParams = true) + { + if (model == null) + { + throw new ArgumentNullException(nameof(model)); + } + if (!withParams) + { + return; + } + if (string.IsNullOrEmpty(model.FoodName)) + { + throw new ArgumentNullException("Нет названия", nameof(model.FoodName)); + } + } + } +} diff --git a/SushiBar/SushiBarBusinessLogic/BusinessLogics/PlaceLogic.cs b/SushiBar/SushiBarBusinessLogic/BusinessLogics/PlaceLogic.cs new file mode 100644 index 0000000..562c4e8 --- /dev/null +++ b/SushiBar/SushiBarBusinessLogic/BusinessLogics/PlaceLogic.cs @@ -0,0 +1,93 @@ +using SushiBarContracts.BindingModels; +using SushiBarContracts.BusinessLogicContracts; +using SushiBarContracts.SearchModels; +using SushiBarContracts.StoragesContracts; +using SushiBarContracts.ViewModels; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace SushiBarBusinessLogic.BusinessLogics +{ + public class PlaceLogic : IPlaceLogic + { + private readonly IPlaceStorage _placeStorage; + + public PlaceLogic(IPlaceStorage placeStorage) + { + _placeStorage = placeStorage; + } + public PlaceViewModel? ReadElement(PlaceSearchModel model) + { + if (model == null) + { + throw new ArgumentNullException(nameof(model)); + } + + var element = _placeStorage.GetElement(model); + if (element == null) + { + return null; + } + return element; + } + + public List? ReadList(PlaceSearchModel? model) + { + var list = model == null ? _placeStorage.GetFullList() : _placeStorage.GetFilteredList(model); + if (list == null) + { + return null; + } + return list; + } + + public bool Create(PlaceBindingModel model) + { + CheckModel(model); + if (_placeStorage.Insert(model) == null) + { + return false; + } + return true; + } + + public bool Delete(PlaceBindingModel model) + { + CheckModel(model, false); + if (_placeStorage.Delete(model) == null) + { + return false; + } + return true; + } + + public bool Update(PlaceBindingModel model) + { + CheckModel(model); + if (_placeStorage.Update(model) == null) + { + return false; + } + return true; + } + + private void CheckModel(PlaceBindingModel model, bool withParams = true) + { + if (model == null) + { + throw new ArgumentNullException(nameof(model)); + } + if (!withParams) + { + return; + } + if (string.IsNullOrEmpty(model.PlaceNumber.ToString())) + { + throw new ArgumentNullException("Нет названия", nameof(model.PlaceNumber)); + } + } + } +} diff --git a/SushiBar/SushiBarBusinessLogic/BusinessLogics/TaskLogic.cs b/SushiBar/SushiBarBusinessLogic/BusinessLogics/TaskLogic.cs new file mode 100644 index 0000000..0502e76 --- /dev/null +++ b/SushiBar/SushiBarBusinessLogic/BusinessLogics/TaskLogic.cs @@ -0,0 +1,89 @@ +using SushiBarContracts.BindingModels; +using SushiBarContracts.BusinessLogicContracts; +using SushiBarContracts.SearchModels; +using SushiBarContracts.StoragesContracts; +using SushiBarContracts.ViewModels; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace SushiBarBusinessLogic.BusinessLogics +{ + public class TaskLogic : ITaskLogic + { + private readonly ITaskStorage _taskStorage; + + public TaskLogic(ITaskStorage taskStorage) + { + _taskStorage = taskStorage; + } + public TaskViewModel? ReadElement(TaskSearchModel model) + { + if (model == null) + { + throw new ArgumentNullException(nameof(model)); + } + + var element = _taskStorage.GetElement(model); + if (element == null) + { + return null; + } + return element; + } + + public List? ReadList(TaskSearchModel? model) + { + var list = model == null ? _taskStorage.GetFullList() : _taskStorage.GetFilteredList(model); + if (list == null) + { + return null; + } + return list; + } + + public bool Create(TaskBindingModel model) + { + CheckModel(model); + if (_taskStorage.Insert(model) == null) + { + return false; + } + return true; + } + + public bool Delete(TaskBindingModel model) + { + CheckModel(model, false); + if (_taskStorage.Delete(model) == null) + { + return false; + } + return true; + } + + public bool Update(TaskBindingModel model) + { + CheckModel(model); + if (_taskStorage.Update(model) == null) + { + return false; + } + return true; + } + + private void CheckModel(TaskBindingModel model, bool withParams = true) + { + if (model == null) + { + throw new ArgumentNullException(nameof(model)); + } + if (!withParams) + { + return; + } + } + } +} diff --git a/SushiBar/SushiBarBusinessLogic/SushiBarBusinessLogic.csproj b/SushiBar/SushiBarBusinessLogic/SushiBarBusinessLogic.csproj new file mode 100644 index 0000000..50a9ff9 --- /dev/null +++ b/SushiBar/SushiBarBusinessLogic/SushiBarBusinessLogic.csproj @@ -0,0 +1,14 @@ + + + + net8.0 + enable + enable + + + + + + + + diff --git a/SushiBar/SushiBarContracts/StoragesContracts/IBuyerStorage.cs b/SushiBar/SushiBarContracts/StoragesContracts/IBuyerStorage.cs index e2dbdb9..56ead99 100644 --- a/SushiBar/SushiBarContracts/StoragesContracts/IBuyerStorage.cs +++ b/SushiBar/SushiBarContracts/StoragesContracts/IBuyerStorage.cs @@ -1,4 +1,5 @@ -using SushiBarContracts.SearchModels; +using SushiBarContracts.BindingModels; +using SushiBarContracts.SearchModels; using SushiBarContracts.ViewModels; using System; using System.Collections.Generic; @@ -14,8 +15,8 @@ namespace SushiBarContracts.StoragesContracts List GetFilteredList(BuyerSearchModel model); BuyerViewModel? GetElement(BuyerSearchModel model); - BuyerViewModel? Insert(BuyerSearchModel model); - BuyerViewModel? Update(BuyerSearchModel model); - BuyerViewModel? Delete(BuyerSearchModel model); + BuyerViewModel? Insert(BuyerBindingModel model); + BuyerViewModel? Update(BuyerBindingModel model); + BuyerViewModel? Delete(BuyerBindingModel model); } } diff --git a/SushiBar/SushiBarContracts/StoragesContracts/ICookStorage.cs b/SushiBar/SushiBarContracts/StoragesContracts/ICookStorage.cs index 6ae4fb6..0273183 100644 --- a/SushiBar/SushiBarContracts/StoragesContracts/ICookStorage.cs +++ b/SushiBar/SushiBarContracts/StoragesContracts/ICookStorage.cs @@ -1,4 +1,5 @@ -using SushiBarContracts.SearchModels; +using SushiBarContracts.BindingModels; +using SushiBarContracts.SearchModels; using SushiBarContracts.ViewModels; using System; using System.Collections.Generic; @@ -14,8 +15,8 @@ namespace SushiBarContracts.StoragesContracts List GetFilteredList(CookSearchModel model); CookViewModel? GetElement(CookSearchModel model); - CookViewModel? Insert(CookSearchModel model); - CookViewModel? Update(CookSearchModel model); - CookViewModel? Delete(CookSearchModel model); + CookViewModel? Insert(CookBindingModel model); + CookViewModel? Update(CookBindingModel model); + CookViewModel? Delete(CookBindingModel model); } } diff --git a/SushiBar/SushiBarContracts/StoragesContracts/IMenuStorage.cs b/SushiBar/SushiBarContracts/StoragesContracts/IMenuStorage.cs index 5832ac1..b5532b5 100644 --- a/SushiBar/SushiBarContracts/StoragesContracts/IMenuStorage.cs +++ b/SushiBar/SushiBarContracts/StoragesContracts/IMenuStorage.cs @@ -1,4 +1,5 @@ -using SushiBarContracts.SearchModels; +using SushiBarContracts.BindingModels; +using SushiBarContracts.SearchModels; using SushiBarContracts.ViewModels; using System; using System.Collections.Generic; @@ -14,8 +15,8 @@ namespace SushiBarContracts.StoragesContracts List GetFilteredList(MenuSearchModel model); MenuViewModel? GetElement(MenuSearchModel model); - MenuViewModel? Insert(MenuSearchModel model); - MenuViewModel? Update(MenuSearchModel model); - MenuViewModel? Delete(MenuSearchModel model); + MenuViewModel? Insert(MenuBindingModel model); + MenuViewModel? Update(MenuBindingModel model); + MenuViewModel? Delete(MenuBindingModel model); } } diff --git a/SushiBar/SushiBarContracts/StoragesContracts/IPlaceStorage.cs b/SushiBar/SushiBarContracts/StoragesContracts/IPlaceStorage.cs index f99444b..6e43ed3 100644 --- a/SushiBar/SushiBarContracts/StoragesContracts/IPlaceStorage.cs +++ b/SushiBar/SushiBarContracts/StoragesContracts/IPlaceStorage.cs @@ -1,4 +1,5 @@ -using SushiBarContracts.SearchModels; +using SushiBarContracts.BindingModels; +using SushiBarContracts.SearchModels; using SushiBarContracts.ViewModels; using System; using System.Collections.Generic; @@ -14,8 +15,8 @@ namespace SushiBarContracts.StoragesContracts List GetFilteredList(PlaceSearchModel model); PlaceViewModel? GetElement(PlaceSearchModel model); - PlaceViewModel? Insert(PlaceSearchModel model); - PlaceViewModel? Update(PlaceSearchModel model); - PlaceViewModel? Delete(PlaceSearchModel model); + PlaceViewModel? Insert(PlaceBindingModel model); + PlaceViewModel? Update(PlaceBindingModel model); + PlaceViewModel? Delete(PlaceBindingModel model); } } diff --git a/SushiBar/SushiBarContracts/StoragesContracts/ITaskStorage.cs b/SushiBar/SushiBarContracts/StoragesContracts/ITaskStorage.cs index da7e129..b5ec446 100644 --- a/SushiBar/SushiBarContracts/StoragesContracts/ITaskStorage.cs +++ b/SushiBar/SushiBarContracts/StoragesContracts/ITaskStorage.cs @@ -1,4 +1,5 @@ -using SushiBarContracts.SearchModels; +using SushiBarContracts.BindingModels; +using SushiBarContracts.SearchModels; using SushiBarContracts.ViewModels; using System; using System.Collections.Generic; @@ -14,8 +15,8 @@ namespace SushiBarContracts.StoragesContracts List GetFilteredList(TaskSearchModel model); TaskViewModel? GetElement(TaskSearchModel model); - TaskViewModel? Insert(TaskSearchModel model); - TaskViewModel? Update(TaskSearchModel model); - TaskViewModel? Delete(TaskSearchModel model); + TaskViewModel? Insert(TaskBindingModel model); + TaskViewModel? Update(TaskBindingModel model); + TaskViewModel? Delete(TaskBindingModel model); } }