From 302bc89cb06ef2e48a70b430ac477a8442f4cc14 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:21 +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=D0=BF=D1=80=D0=BE=D1=86?= =?UTF-8?q?=D0=B5=D0=B4=D1=83=D1=80=D1=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../BusinessLogics/ProcedureLogic.cs | 90 +++++++++++++++++-- 1 file changed, 84 insertions(+), 6 deletions(-) diff --git a/Polyclinic/PolyclinicBusinessLogic/BusinessLogics/ProcedureLogic.cs b/Polyclinic/PolyclinicBusinessLogic/BusinessLogics/ProcedureLogic.cs index c4f386d..789738b 100644 --- a/Polyclinic/PolyclinicBusinessLogic/BusinessLogics/ProcedureLogic.cs +++ b/Polyclinic/PolyclinicBusinessLogic/BusinessLogics/ProcedureLogic.cs @@ -1,35 +1,113 @@ -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 ProcedureLogic : IProcedureLogic { + + private readonly ILogger logger; + private readonly IProcedureStorage procedureStorage; + + public ProcedureLogic(ILogger logger, IProcedureStorage procedureStorage) + { + this.logger = logger; + this.procedureStorage = procedureStorage; + } public bool Create(ProcedureBindingModel model) { - throw new NotImplementedException(); + CheckModel(model); + if (procedureStorage.Insert(model) == null) + { + logger.LogWarning("Insert operation failed"); + return false; + } + return true; } public bool Delete(ProcedureBindingModel model) { - throw new NotImplementedException(); + CheckModel(model, false); + + logger.LogInformation("Delete Id:{Id}", model.Id); + if(procedureStorage.Delete(model) == null) + { + logger.LogWarning("Delete operation failed"); + return false; + } + return true; } public ProcedureViewModel? ReadElement(ProcedureSearchModel model) { - throw new NotImplementedException(); + if (model == null) + { + throw new ArgumentNullException(nameof(model)); + } + logger.LogInformation("ReadElement. ProcedureName:{ProcedureName}.Id:{ Id}", model.Name, model.Id); + var element = procedureStorage.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(ProcedureSearchModel? model) { - throw new NotImplementedException(); + logger.LogInformation("ReadList. Name:{Name}. Id:{ Id}", model?.Name, model?.Id); + var list = model == null ? procedureStorage.GetFullList() : procedureStorage.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(ProcedureBindingModel model) { - throw new NotImplementedException(); + CheckModel(model); + if (procedureStorage.Update(model) == null) + { + logger.LogWarning("Update operation failed"); + return false; + } + return true; + } + + private void CheckModel(ProcedureBindingModel model, bool withParams = true) + { + if (model == null) + { + throw new ArgumentNullException(nameof(model)); + } + if (!withParams) + { + return; + } + if (string.IsNullOrEmpty(model.Name)) + { + throw new ArgumentNullException("Нет названия процедуры", nameof(model.Name)); + } + logger.LogInformation("Procedure. Name:{Name}. Id: { Id}", model.Name, model.Id); + + var element = procedureStorage.GetElement(new ProcedureSearchModel + { + Name = model.Name + }); + + if (element != null && element.Id != model.Id) + { + throw new InvalidOperationException("Процедура с таким названием уже есть"); + } } } }