From 745dbe385f6907bc709ee0a5a392dfb448950d02 Mon Sep 17 00:00:00 2001 From: ekallin Date: Sun, 10 Mar 2024 18:26:10 +0400 Subject: [PATCH] =?UTF-8?q?=D0=B4=D0=BE=D0=B1=D0=B0=D0=B2=D0=BB=D0=B5?= =?UTF-8?q?=D0=BD=D1=8B=20=D1=84=D0=B0=D0=B9=D0=BB=D1=8B=20=D0=B2=20=D0=BF?= =?UTF-8?q?=D1=80=D0=BE=D0=B5=D0=BA=D1=82=20..Contracts=20=D0=B8=20=D0=BD?= =?UTF-8?q?=D0=B0=D1=87=D0=B0=D1=82=D0=B0=20=D0=BB=D0=BE=D0=B3=D0=B8=D0=BA?= =?UTF-8?q?=D0=B0=20=D0=BC=D0=B0=D0=B3=D0=B0=D0=B7=D0=B8=D0=BD=D0=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- SushiBarBusinessLogic/ShopLogic.cs | 70 +++++++++++++++++++ .../BindingModel/ShopBindingModel.cs | 14 ++++ .../BusinessLogicsContracts/IShopLogic.cs | 17 +++++ .../SearchModel/ShopSearchModel.cs | 8 +++ .../StoragesContracts/IShopStorage.cs | 16 +++++ SushiBarContracts/ViewModels/ShopViewModel.cs | 21 ++++++ SushiBarDataModels/IShopModel.cs | 8 +-- SushiBarDataModels/ShopBindingModel.cs | 6 ++ 8 files changed, 156 insertions(+), 4 deletions(-) create mode 100644 SushiBarBusinessLogic/ShopLogic.cs create mode 100644 SushiBarContracts/BindingModel/ShopBindingModel.cs create mode 100644 SushiBarContracts/BusinessLogicsContracts/IShopLogic.cs create mode 100644 SushiBarContracts/SearchModel/ShopSearchModel.cs create mode 100644 SushiBarContracts/StoragesContracts/IShopStorage.cs create mode 100644 SushiBarContracts/ViewModels/ShopViewModel.cs create mode 100644 SushiBarDataModels/ShopBindingModel.cs diff --git a/SushiBarBusinessLogic/ShopLogic.cs b/SushiBarBusinessLogic/ShopLogic.cs new file mode 100644 index 0000000..b4931b8 --- /dev/null +++ b/SushiBarBusinessLogic/ShopLogic.cs @@ -0,0 +1,70 @@ +using Microsoft.Extensions.Logging; +using SushiBarContracts.BindingModel; +using SushiBarContracts.BusinessLogicsContracts; +using SushiBarContracts.SearchModel; +using SushiBarContracts.StoragesContracts; +using SushiBarContracts.ViewModels; +using SushiBarDataModels; + +namespace SushiBarBusinessLogic +{ + public class ShopLogic : IShopLogic + { + private readonly ILogger _logger; + private readonly IShopStorage _shopStorage; + + public ShopLogic(ILogger logger, IShopStorage shopStorage) + { + _logger = logger; + _shopStorage = shopStorage; + } + + public List? ReadList(ShopSearchModel? model) + { + _logger.LogInformation("ReadList. Id:{ Id}, ShopName:{ ShopName}", model?.Id, model?.Name); + var list = model == null ? _shopStorage.GetFullList() : _shopStorage.GetFilteredList(model); + if (list == null) + { + _logger.LogWarning("ReadList return null list"); + return null; + } + _logger.LogInformation("ReadList. Count:{Count}", list.Count); + return list; + } + + public ShopViewModel? ReadElement(ShopSearchModel model) + { + if (model == null) + { + throw new ArgumentNullException(nameof(model)); + } + _logger.LogInformation("ReadList. Id:{ Id}, ShopName:{ ShopName}", model.Id, model.Name); + var element = _shopStorage.GetElement(model); + if (element == null) + { + _logger.LogWarning("ReadElement element not found"); + return null; + } + _logger.LogInformation("ReadElement find. Id:{Id}", element.Id); + return element; + } + + public bool Create(ShopBindingModel model) + { + CheckModel(model); + } + + private bool CheckModel(ShopBindingModel model, bool withParams = true) + { + if(model == null) + throw new ArgumentNullException($"{nameof(model)} is null"); + if (!withParams) return false; + if (string.IsNullOrEmpty(model.Name)) + { + throw new ArgumentNullException("Нет такого магазина", nameof(model.Name)); + } + _logger.LogInformation("Shop. ShopName:{ShopName}.Address:{ Address}. Id:{ Id}", + model.ShopName, model.Address, model.Id); + } + } +} diff --git a/SushiBarContracts/BindingModel/ShopBindingModel.cs b/SushiBarContracts/BindingModel/ShopBindingModel.cs new file mode 100644 index 0000000..c27c14a --- /dev/null +++ b/SushiBarContracts/BindingModel/ShopBindingModel.cs @@ -0,0 +1,14 @@ +using SushiBarDataModels; +using SushiBarDataModels.Models; + +namespace SushiBarContracts.BindingModel +{ + public class ShopBindingModel : IShopModel + { + public int Id { get; set; } + public string Name { get; set; } + public string Address { get; set; } + public DateTime DateOpening { get; set; } = DateTime.Now; + public Dictionary ShopSushis { get; set; } = new(); + } +} diff --git a/SushiBarContracts/BusinessLogicsContracts/IShopLogic.cs b/SushiBarContracts/BusinessLogicsContracts/IShopLogic.cs new file mode 100644 index 0000000..cc71895 --- /dev/null +++ b/SushiBarContracts/BusinessLogicsContracts/IShopLogic.cs @@ -0,0 +1,17 @@ +using SushiBarContracts.BindingModel; +using SushiBarContracts.SearchModel; +using SushiBarContracts.ViewModels; +using SushiBarDataModels.Models; + +namespace SushiBarContracts.BusinessLogicsContracts +{ + public interface IShopLogic + { + List? ReadList(ShopSearchModel? model); + ShopViewModel? ReadElement(ShopSearchModel model); + bool Create(ShopBindingModel model); + bool Update(ShopBindingModel model); + bool Delete(ShopBindingModel model); + bool AddSushiInShop(ShopSearchModel model, ISushiModel sushi, int count); + } +} diff --git a/SushiBarContracts/SearchModel/ShopSearchModel.cs b/SushiBarContracts/SearchModel/ShopSearchModel.cs new file mode 100644 index 0000000..f34d7e5 --- /dev/null +++ b/SushiBarContracts/SearchModel/ShopSearchModel.cs @@ -0,0 +1,8 @@ +namespace SushiBarContracts.SearchModel +{ + public class ShopSearchModel + { + public int? Id { get; set; } + public string? Name { get; set; } + } +} diff --git a/SushiBarContracts/StoragesContracts/IShopStorage.cs b/SushiBarContracts/StoragesContracts/IShopStorage.cs new file mode 100644 index 0000000..dfa1b73 --- /dev/null +++ b/SushiBarContracts/StoragesContracts/IShopStorage.cs @@ -0,0 +1,16 @@ +using SushiBarContracts.BindingModel; +using SushiBarContracts.SearchModel; +using SushiBarContracts.ViewModels; + +namespace SushiBarContracts.StoragesContracts +{ + public interface IShopStorage + { + List GetFullList(); + List GetFilteredList(ShopSearchModel model); + ShopViewModel? GetElement(ShopSearchModel model); + ShopViewModel? Insert(ShopBindingModel model); + ShopViewModel? Update(ShopBindingModel model); + ShopViewModel? Delete(ShopBindingModel model); + } +} diff --git a/SushiBarContracts/ViewModels/ShopViewModel.cs b/SushiBarContracts/ViewModels/ShopViewModel.cs new file mode 100644 index 0000000..09b0864 --- /dev/null +++ b/SushiBarContracts/ViewModels/ShopViewModel.cs @@ -0,0 +1,21 @@ +using SushiBarDataModels; +using SushiBarDataModels.Models; +using System.ComponentModel; + +namespace SushiBarContracts.ViewModels +{ + public class ShopViewModel : IShopModel + { + public int Id { get; set; } + + [DisplayName("Название магазина")] + public string Name { get; set; } = string.Empty; + + [DisplayName("Адрес")] + public string Address { get; set; } = string.Empty; + + [DisplayName("Дата открытия")] + public DateTime DateOpening { get; set; } = DateTime.Now; + public Dictionary ShopSushis { get; set; } = new(); + } +} diff --git a/SushiBarDataModels/IShopModel.cs b/SushiBarDataModels/IShopModel.cs index d74165e..cd01a16 100644 --- a/SushiBarDataModels/IShopModel.cs +++ b/SushiBarDataModels/IShopModel.cs @@ -4,9 +4,9 @@ namespace SushiBarDataModels { public interface IShopModel : IId { - string Name { get; set; } - string Address { get; set; } - DateTime DateOpening { get; set; } - Dictionary ShopSushis{ get; set; } + string Name { get; } + string Address { get; } + DateTime DateOpening { get; } + Dictionary ShopSushis{ get; } } } diff --git a/SushiBarDataModels/ShopBindingModel.cs b/SushiBarDataModels/ShopBindingModel.cs new file mode 100644 index 0000000..fab6768 --- /dev/null +++ b/SushiBarDataModels/ShopBindingModel.cs @@ -0,0 +1,6 @@ +namespace SushiBarDataModels +{ + public class ShopBindingModel : IShopModel + { + } +}