From 185bf52db8fa6e35cf5d7dcf83c6b001f2f4cb82 Mon Sep 17 00:00:00 2001 From: "ns.potapov" Date: Mon, 29 Apr 2024 23:14:16 +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=BA=D1=83=D1=80=D1=81=D0=BE=D0=B2=20=D0=BF=D1=80=D0=B8=D0=B5?= =?UTF-8?q?=D0=BC=D0=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../BusinessLogics/CourseLogic.cs | 82 +++++++++++++++++-- 1 file changed, 76 insertions(+), 6 deletions(-) diff --git a/Polyclinic/PolyclinicBusinessLogic/BusinessLogics/CourseLogic.cs b/Polyclinic/PolyclinicBusinessLogic/BusinessLogics/CourseLogic.cs index 090a167..d78f272 100644 --- a/Polyclinic/PolyclinicBusinessLogic/BusinessLogics/CourseLogic.cs +++ b/Polyclinic/PolyclinicBusinessLogic/BusinessLogics/CourseLogic.cs @@ -1,35 +1,105 @@ -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 CourseLogic : ICourseLogic { + private ILogger _logger; + private ICourseStorage _courseStorage; + + public CourseLogic(ILogger logger, ICourseStorage courseStorage) + { + _logger = logger; + _courseStorage = courseStorage; + } + public bool Create(CourseBindingModel model) { - throw new NotImplementedException(); + CheckModel(model); + if (_courseStorage.Insert(model) == null) + { + _logger.LogWarning("Insert operation failed"); + return false; + } + return true; } public bool Delete(CourseBindingModel model) { - throw new NotImplementedException(); + CheckModel(model, false); + _logger.LogInformation("Delete. Id:{Id}", model.Id); + if (_courseStorage.Delete(model) == null) + { + _logger.LogWarning("Delete operation failed"); + return false; + } + return true; } public CourseViewModel? ReadElement(CourseSearchModel model) { - throw new NotImplementedException(); + if (model == null) + { + throw new ArgumentNullException(nameof(model)); + } + _logger.LogInformation("ReadElement. Id:{Id}", model.Id); + var element = _courseStorage.GetElement(model); + if (element == null) + { + _logger.LogWarning("ReadElement element not found"); + return null; + } + _logger.LogInformation("ReadElement. Id:{Id}", element.Id); + return element; } public List? ReadList(CourseSearchModel? model) { - throw new NotImplementedException(); + _logger.LogInformation("ReadList. Id:{Id}", model?.Id); + var list = model == null ? _courseStorage.GetFullList() : _courseStorage.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(CourseBindingModel model) { - throw new NotImplementedException(); + CheckModel(model); + if (_courseStorage.Update(model) == null) + { + _logger.LogWarning("Update operation failed"); + return false; + } + return true; + } + private void CheckModel(CourseBindingModel model, bool withParams = true) + { + if (model == null) + { + throw new ArgumentNullException(nameof(model)); + } + if (!withParams) + { + return; + } + if (model.DaysCount < 1) + { + throw new ArgumentNullException("Количество дней приема должно быть больше нуля", nameof(model.DaysCount)); + } + if (model.PillsPerDay < 1) + { + throw new ArgumentNullException("Количество препарата в день должно быть больше нуля", nameof(model.PillsPerDay)); + } + _logger.LogInformation("Course. Id: {Id}", model.Id); } } }