From f3b5d4f960683831452422d150b7987d4ea7ae00 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=95=D0=BB=D0=B5=D0=BD=D0=B0=20=D0=91=D0=B0=D0=BA=D0=B0?= =?UTF-8?q?=D0=BB=D1=8C=D1=81=D0=BA=D0=B0=D1=8F?= Date: Mon, 29 Apr 2024 22:50:40 +0400 Subject: [PATCH] =?UTF-8?q?=D1=80=D0=B5=D0=B0=D0=BB=D0=B8=D0=B7=D0=BE?= =?UTF-8?q?=D0=B2=D0=B0=D0=BB=D0=B0=20=D0=BA=D0=BB=D0=B0=D1=81=D1=81=20?= =?UTF-8?q?=D0=B1=D0=B8=D0=B7=D0=BD=D0=B5=D1=81-=D0=BB=D0=BE=D0=B3=D0=B8?= =?UTF-8?q?=D0=BA=D0=B8=20=D0=B4=D0=BB=D1=8F=20=D1=80=D0=B5=D1=86=D0=B5?= =?UTF-8?q?=D0=BF=D1=82=D0=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../BusinessLogics/RecipeLogic.cs | 83 +++++++++++++++++-- .../PolyclinicBusinessLogic.csproj | 4 + 2 files changed, 81 insertions(+), 6 deletions(-) diff --git a/Polyclinic/PolyclinicBusinessLogic/BusinessLogics/RecipeLogic.cs b/Polyclinic/PolyclinicBusinessLogic/BusinessLogics/RecipeLogic.cs index da383ab..7f5c66c 100644 --- a/Polyclinic/PolyclinicBusinessLogic/BusinessLogics/RecipeLogic.cs +++ b/Polyclinic/PolyclinicBusinessLogic/BusinessLogics/RecipeLogic.cs @@ -1,35 +1,106 @@ -using PolyclinicContracts.BindingModels; +using Microsoft.Extensions.Logging; +using PolyclinicContracts.BindingModels; using PolyclinicContracts.BusinessLogicsContracts; using PolyclinicContracts.SearchModels; +using PolyclinicContracts.StoragesContracts; using PolyclinicContracts.ViewModels; namespace PolyclinicBusinessLogic.BusinessLogics { public class RecipeLogic : IRecipeLogic { + + private readonly ILogger logger; + private readonly IRecipeStorage recipeStorage; + + public RecipeLogic(ILogger logger, IRecipeStorage recipeStorage) + { + this.logger = logger; + this.recipeStorage = recipeStorage; + } public bool Create(RecipeBindingModel model) { - throw new NotImplementedException(); + CheckModel(model); + if(recipeStorage.Insert(model) == null) + { + logger.LogWarning("Create operation failed"); + return false; + } + return true; } public bool Delete(RecipeBindingModel model) { - throw new NotImplementedException(); + CheckModel(model, false); + if(recipeStorage.Delete(model) == null) + { + logger.LogWarning("Delete operation failed"); + return false; + } + logger.LogInformation("Delete Id:{Id}", model.Id); + return true; } public RecipeViewModel? ReadElement(RecipeSearchModel model) { - throw new NotImplementedException(); + if (model == null) + { + throw new ArgumentNullException(nameof(model)); + } + logger.LogInformation("ReadElement. Comment:{Comment}.Id:{ Id}", model.Comment, model.Id); + var element = recipeStorage.GetElement(model); + if (element == null) + { + logger.LogWarning("ReadElement element not found"); + return null; + } + logger.LogInformation("ReadElement find. Id:{Id}", element.Id); + return element; } public List? ReadList(RecipeSearchModel? model) { - throw new NotImplementedException(); + logger.LogInformation("ReadList. Comment:{Comment}. Id:{ Id}", model?.Comment, model?.Id); + var list = model == null ? recipeStorage.GetFullList() : recipeStorage.GetFilteredList(model); + if (list == null) + { + logger.LogWarning("ReadList return null list"); + return null; + } + logger.LogInformation("ReadList. Count:{Count}", list.Count); + return list; } public bool Update(RecipeBindingModel model) { - throw new NotImplementedException(); + CheckModel(model); + if(recipeStorage.Update(model) == null) + { + logger.LogWarning("Update operation failed"); + return false; + } + return true; + } + + private void CheckModel(RecipeBindingModel model, bool withParams = true) + { + if (model == null) + { + throw new ArgumentNullException(nameof(model)); + } + if (!withParams) + { + return; + } + if(model.ProceduresCount <= 0) + { + throw new ArgumentNullException("Количество процедур не может быть равно нулю или быть меньше нуля", nameof(model)); + } + if (string.IsNullOrEmpty(model.Comment)) + { + throw new ArgumentNullException("Нет комментария", nameof(model.Comment)); + } + logger.LogInformation("Recipe. Comment:{Comment}. Id: { Id}", model.Comment, model.Id); } } } diff --git a/Polyclinic/PolyclinicBusinessLogic/PolyclinicBusinessLogic.csproj b/Polyclinic/PolyclinicBusinessLogic/PolyclinicBusinessLogic.csproj index 82ea6fe..329c997 100644 --- a/Polyclinic/PolyclinicBusinessLogic/PolyclinicBusinessLogic.csproj +++ b/Polyclinic/PolyclinicBusinessLogic/PolyclinicBusinessLogic.csproj @@ -6,6 +6,10 @@ enable + + + +