From ca063f06e04c9d2ab81ab90d25701e70487c053b Mon Sep 17 00:00:00 2001 From: "ns.potapov" Date: Mon, 29 Apr 2024 22:34:54 +0400 Subject: [PATCH] =?UTF-8?q?=D0=A0=D0=B5=D0=B0=D0=BB=D0=B8=D0=B7=D0=BE?= =?UTF-8?q?=D0=B2=D0=B0=D0=BB=20=D0=BB=D0=BE=D0=B3=D0=B8=D0=BA=D1=83=20?= =?UTF-8?q?=D0=B1=D0=BE=D0=BB=D0=B5=D0=B7=D0=BD=D0=B5=D0=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../BusinessLogics/SymptomLogic.cs | 86 +++++++++++++++++-- .../SearchModels/SymptomSearchModel.cs | 1 + 2 files changed, 81 insertions(+), 6 deletions(-) diff --git a/Polyclinic/PolyclinicBusinessLogic/BusinessLogics/SymptomLogic.cs b/Polyclinic/PolyclinicBusinessLogic/BusinessLogics/SymptomLogic.cs index fb6d9b6..cab88fa 100644 --- a/Polyclinic/PolyclinicBusinessLogic/BusinessLogics/SymptomLogic.cs +++ b/Polyclinic/PolyclinicBusinessLogic/BusinessLogics/SymptomLogic.cs @@ -1,35 +1,109 @@ -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 SymptomLogic : ISymptomLogic { + private ILogger _logger; + private ISymptomStorage _symptomStorage; + + public SymptomLogic(ILogger logger, ISymptomStorage symptomStorage) + { + _logger = logger; + _symptomStorage = symptomStorage; + } + public bool Create(SymptomBindingModel model) { - throw new NotImplementedException(); + CheckModel(model); + if (_symptomStorage.Insert(model) == null) + { + _logger.LogWarning("Insert operation failed"); + return false; + } + return true; } public bool Delete(SymptomBindingModel model) { - throw new NotImplementedException(); + CheckModel(model, false); + _logger.LogInformation("Delete. Name:{Name}, Id:{Id}", model.Name, model.Id); + if (_symptomStorage.Delete(model) == null) + { + _logger.LogWarning("Delete operation failed"); + return false; + } + return true; } public SymptomViewModel? ReadElement(SymptomSearchModel model) { - throw new NotImplementedException(); + if (model == null) + { + throw new ArgumentNullException(nameof(model)); + } + _logger.LogInformation("ReadElement. Name:{Name}, Id:{Id}", model.Name, model.Id); + var element = _symptomStorage.GetElement(model); + if (element == null) + { + _logger.LogWarning("ReadElement element not found"); + return null; + } + _logger.LogInformation("ReadElement find. Name:{Name}, Id:{Id}", element.Name, element.Id); + return element; } public List? ReadList(SymptomSearchModel? model) { - throw new NotImplementedException(); + _logger.LogInformation("ReadList. Name:{Name} Id:{Id}", model?.Name, model?.Id); + var list = model == null ? _symptomStorage.GetFullList() : _symptomStorage.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(SymptomBindingModel model) { - throw new NotImplementedException(); + CheckModel(model); + if (_symptomStorage.Update(model) == null) + { + _logger.LogWarning("Update operation failed"); + return false; + } + return true; + } + private void CheckModel(SymptomBindingModel 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("Symptom. Name:{Name}. Id: {Id}", model.Name, model.Id); + var element = _symptomStorage.GetElement(new SymptomSearchModel + { + Name = model.Name + }); + if (element != null && element.Id != model.Id) + { + throw new InvalidOperationException("Болезнь с таким названием уже есть"); + } } } } diff --git a/Polyclinic/PolyclinicContracts/SearchModels/SymptomSearchModel.cs b/Polyclinic/PolyclinicContracts/SearchModels/SymptomSearchModel.cs index 156f028..8131037 100644 --- a/Polyclinic/PolyclinicContracts/SearchModels/SymptomSearchModel.cs +++ b/Polyclinic/PolyclinicContracts/SearchModels/SymptomSearchModel.cs @@ -3,5 +3,6 @@ public class SymptomSearchModel { public int? Id { get; set; } + public string?Name { get; set; } } }