From d9c9cf410a119c060357794709a8dc71a88456c7 Mon Sep 17 00:00:00 2001 From: prodigygirl Date: Thu, 6 Apr 2023 13:34:53 +0400 Subject: [PATCH] =?UTF-8?q?=D0=AD=D1=82=D0=B0=D0=BF=204.=20=D0=91=D0=B8?= =?UTF-8?q?=D0=B7=D0=BD=D0=B5=D1=81-=D0=BB=D0=BE=D0=B3=D0=B8=D0=BA=D0=B0?= =?UTF-8?q?=20=D0=B1=D0=B5=D0=B7=20=D0=BE=D1=82=D1=87=D0=B5=D1=82=D0=BE?= =?UTF-8?q?=D0=B2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Hospital/Hospital.sln | 14 ++- .../HospitalBusinessLogic/ApothecaryLogic.cs | 119 ++++++++++++++++++ .../HospitalBusinessLogic.csproj | 20 +++ .../HospitalBusinessLogic/MedicineLogic.cs | 113 +++++++++++++++++ .../HospitalBusinessLogic/PatientLogic.cs | 111 ++++++++++++++++ .../PrescriptionLogic.cs | 103 +++++++++++++++ .../HospitalBusinessLogic/ProcedureLogic.cs | 108 ++++++++++++++++ Hospital/HospitalBusinessLogic/RecipeLogic.cs | 103 +++++++++++++++ .../HospitalBusinessLogic/TreatmentLogic.cs | 104 +++++++++++++++ Hospital/HospitalWeb/HospitalWeb.csproj | 13 ++ 10 files changed, 807 insertions(+), 1 deletion(-) create mode 100644 Hospital/HospitalBusinessLogic/ApothecaryLogic.cs create mode 100644 Hospital/HospitalBusinessLogic/HospitalBusinessLogic.csproj create mode 100644 Hospital/HospitalBusinessLogic/MedicineLogic.cs create mode 100644 Hospital/HospitalBusinessLogic/PatientLogic.cs create mode 100644 Hospital/HospitalBusinessLogic/PrescriptionLogic.cs create mode 100644 Hospital/HospitalBusinessLogic/ProcedureLogic.cs create mode 100644 Hospital/HospitalBusinessLogic/RecipeLogic.cs create mode 100644 Hospital/HospitalBusinessLogic/TreatmentLogic.cs diff --git a/Hospital/Hospital.sln b/Hospital/Hospital.sln index 9487b59..509d58b 100644 --- a/Hospital/Hospital.sln +++ b/Hospital/Hospital.sln @@ -9,7 +9,11 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "HospitalDataModels", "Hospi EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "HospitalContracts", "HospitalContracts\HospitalContracts.csproj", "{F24FE3B9-EA65-4793-A950-68857BCC7DB2}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "HospitalDatabaseImplement", "HospitalDatabaseImplement\HospitalDatabaseImplement.csproj", "{B99AB6C1-2F4F-4E40-B933-45CE5E6CC37B}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "HospitalDatabaseImplement", "HospitalDatabaseImplement\HospitalDatabaseImplement.csproj", "{B99AB6C1-2F4F-4E40-B933-45CE5E6CC37B}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "HospitalBusinessLogic", "HospitalBusinessLogic\HospitalBusinessLogic.csproj", "{C8819EE4-365C-4960-9578-3B8A45B5EBF4}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "UnitTest", "UnitTest\UnitTest.csproj", "{A8EB3C34-5C9B-4C40-8B0F-21D62ACBFFFF}" EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution @@ -33,6 +37,14 @@ Global {B99AB6C1-2F4F-4E40-B933-45CE5E6CC37B}.Debug|Any CPU.Build.0 = Debug|Any CPU {B99AB6C1-2F4F-4E40-B933-45CE5E6CC37B}.Release|Any CPU.ActiveCfg = Release|Any CPU {B99AB6C1-2F4F-4E40-B933-45CE5E6CC37B}.Release|Any CPU.Build.0 = Release|Any CPU + {C8819EE4-365C-4960-9578-3B8A45B5EBF4}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {C8819EE4-365C-4960-9578-3B8A45B5EBF4}.Debug|Any CPU.Build.0 = Debug|Any CPU + {C8819EE4-365C-4960-9578-3B8A45B5EBF4}.Release|Any CPU.ActiveCfg = Release|Any CPU + {C8819EE4-365C-4960-9578-3B8A45B5EBF4}.Release|Any CPU.Build.0 = Release|Any CPU + {A8EB3C34-5C9B-4C40-8B0F-21D62ACBFFFF}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {A8EB3C34-5C9B-4C40-8B0F-21D62ACBFFFF}.Debug|Any CPU.Build.0 = Debug|Any CPU + {A8EB3C34-5C9B-4C40-8B0F-21D62ACBFFFF}.Release|Any CPU.ActiveCfg = Release|Any CPU + {A8EB3C34-5C9B-4C40-8B0F-21D62ACBFFFF}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE diff --git a/Hospital/HospitalBusinessLogic/ApothecaryLogic.cs b/Hospital/HospitalBusinessLogic/ApothecaryLogic.cs new file mode 100644 index 0000000..ddf0a90 --- /dev/null +++ b/Hospital/HospitalBusinessLogic/ApothecaryLogic.cs @@ -0,0 +1,119 @@ +using HospitalContracts.BindingModels; +using HospitalContracts.BusinessLogicContracts; +using HospitalContracts.SearchModels; +using HospitalContracts.StorageContracts; +using HospitalContracts.ViewModels; +using Microsoft.Extensions.Logging; + +namespace HospitalBusinessLogic +{ + public class ApothecaryLogic : IApothecaryLogic + { + private readonly ILogger _logger; + private readonly IApothecaryStorage _apothecaryStorage; + + public ApothecaryLogic(ILogger logger, IApothecaryStorage apothecaryStorage) + { + _logger = logger; + _apothecaryStorage = apothecaryStorage; + } + + public ApothecaryViewModel? ReadElement(ApothecarySearchModel model) + { + if (model == null) + { + throw new ArgumentNullException(nameof(model)); + } + _logger.LogInformation("ReadElement. Login: {Login} Id:{ Id}", model.Login, model.Id); + var element = _apothecaryStorage.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(ApothecarySearchModel? model) + { + _logger.LogInformation("ReadList. Login: {Login}. Id:{ Id}", model?.Login, model?.Id); + var list = model == null ? _apothecaryStorage.GetFullList() : _apothecaryStorage.GetFilteredList(model); + if (list == null) + { + _logger.LogWarning("ReadList return null list"); + return null; + } + _logger.LogInformation("ReadList. Count:{Count}", list.Count); + return list; + } + + public bool Create(ApothecaryBindingModel model) + { + CheckModel(model); + if (_apothecaryStorage.Insert(model) == null) + { + _logger.LogWarning("Insert operation failed"); + return false; + } + return true; + } + + public bool Delete(ApothecaryBindingModel model) + { + CheckModel(model, false); + _logger.LogInformation("Delete. Id:{Id}", model.Id); + if (_apothecaryStorage.Delete(model) == null) + { + _logger.LogWarning("Delete operation failed"); + return false; + } + return true; + } + + public bool Update(ApothecaryBindingModel model) + { + CheckModel(model); + if (_apothecaryStorage.Update(model) == null) + { + _logger.LogWarning("Update operation failed"); + return false; + } + return true; + } + + private void CheckModel(ApothecaryBindingModel model, bool withParams = true) + { + if (model == null) + { + throw new ArgumentNullException(nameof(model)); + } + if (!withParams) + { + return; + } + + if (string.IsNullOrEmpty(model.Login)) + { + throw new ArgumentNullException("Нет логина пользователя", + nameof(model.Login)); + } + if (string.IsNullOrEmpty(model.Password)) + { + throw new ArgumentNullException("Нет пароля пользователя", + nameof(model.Password)); + } + if (model.Password.Length < 5 || model.Password.Length > 15) + { + throw new ArgumentNullException("Пароль должен иметь длину от 5 до 15 символов", + nameof(model.Password)); + } + _logger.LogInformation("Apothecary. Login:{ Login}. Id: { Id}", model.Login, model.Id); + var element = _apothecaryStorage.GetElement(new ApothecarySearchModel { Login = model.Login }); + if (element != null && element.Id != model.Id) + { + throw new InvalidOperationException("Пользователь с таким логином уже есть"); + } + } + } +} diff --git a/Hospital/HospitalBusinessLogic/HospitalBusinessLogic.csproj b/Hospital/HospitalBusinessLogic/HospitalBusinessLogic.csproj new file mode 100644 index 0000000..d396a6c --- /dev/null +++ b/Hospital/HospitalBusinessLogic/HospitalBusinessLogic.csproj @@ -0,0 +1,20 @@ + + + + net6.0 + enable + enable + + + + + + + + + + + + + + diff --git a/Hospital/HospitalBusinessLogic/MedicineLogic.cs b/Hospital/HospitalBusinessLogic/MedicineLogic.cs new file mode 100644 index 0000000..608d037 --- /dev/null +++ b/Hospital/HospitalBusinessLogic/MedicineLogic.cs @@ -0,0 +1,113 @@ +using HospitalContracts.BindingModels; +using HospitalContracts.BusinessLogicContracts; +using HospitalContracts.SearchModels; +using HospitalContracts.StorageContracts; +using HospitalContracts.ViewModels; +using Microsoft.Extensions.Logging; + +namespace HospitalBusinessLogic +{ + public class MedicineLogic : IMedicineLogic + { + private readonly ILogger _logger; + private readonly IMedicineStorage _medicineStorage; + + public MedicineLogic(ILogger logger, IMedicineStorage medicineStorage) + { + _logger = logger; + _medicineStorage = medicineStorage; + } + + public MedicineViewModel? ReadElement(MedicineSearchModel model) + { + if (model == null) + { + throw new ArgumentNullException(nameof(model)); + } + _logger.LogInformation("ReadElement. Name: {Name}. Id:{ Id}", model.Name, model.Id); + var element = _medicineStorage.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(MedicineSearchModel? model) + { + _logger.LogInformation("ReadList. Name: {Name}. Id:{ Id}", model?.Name, model?.Id); + var list = model == null ? _medicineStorage.GetFullList() : _medicineStorage.GetFilteredList(model); + if (list == null) + { + _logger.LogWarning("ReadList return null list"); + return null; + } + _logger.LogInformation("ReadList. Count:{Count}", list.Count); + return list; + } + + public bool Create(MedicineBindingModel model) + { + CheckModel(model); + if (_medicineStorage.Insert(model) == null) + { + _logger.LogWarning("Insert operation failed"); + return false; + } + return true; + } + + public bool Delete(MedicineBindingModel model) + { + CheckModel(model, false); + _logger.LogInformation("Delete. Id:{Id}", model.Id); + if (_medicineStorage.Delete(model) == null) + { + _logger.LogWarning("Delete operation failed"); + return false; + } + return true; + } + + public bool Update(MedicineBindingModel model) + { + CheckModel(model); + if (_medicineStorage.Update(model) == null) + { + _logger.LogWarning("Update operation failed"); + return false; + } + return true; + } + + private void CheckModel(MedicineBindingModel 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)); + } + if (model.Cost <= 0) + { + throw new ArgumentNullException("Стоимость лекарства должна быть больше 0", + nameof(model.Cost)); + } + if (string.IsNullOrEmpty(model.Dose)) + { + throw new ArgumentNullException("Нет дозировки лекарства", + nameof(model.Dose)); + } + _logger.LogInformation("Medicine. Name:{ Name}. Cost: {Cost}. Dose: {Dose}. Id: { Id}", model.Name, model.Cost, model.Dose, model.Id); + } + } +} diff --git a/Hospital/HospitalBusinessLogic/PatientLogic.cs b/Hospital/HospitalBusinessLogic/PatientLogic.cs new file mode 100644 index 0000000..cbd7c37 --- /dev/null +++ b/Hospital/HospitalBusinessLogic/PatientLogic.cs @@ -0,0 +1,111 @@ +using HospitalContracts.BindingModels; +using HospitalContracts.BusinessLogicContracts; +using HospitalContracts.SearchModels; +using HospitalContracts.StorageContracts; +using HospitalContracts.ViewModels; +using Microsoft.Extensions.Logging; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace HospitalBusinessLogic +{ + public class PatientLogic : IPatientLogic + { + private readonly ILogger _logger; + private readonly IPatientStorage _patientStorage; + + public PatientLogic(ILogger logger, IPatientStorage patientStorage) + { + _logger = logger; + _patientStorage = patientStorage; + } + + public PatientViewModel? ReadElement(PatientSearchModel model) + { + if (model == null) + { + throw new ArgumentNullException(nameof(model)); + } + _logger.LogInformation("ReadElement. Id:{ Id}", model.Id); + var element = _patientStorage.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(PatientSearchModel? model) + { + _logger.LogInformation("ReadList. Id:{ Id}", model?.Id); + var list = model == null ? _patientStorage.GetFullList() : _patientStorage.GetFilteredList(model); + if (list == null) + { + _logger.LogWarning("ReadList return null list"); + return null; + } + _logger.LogInformation("ReadList. Count:{Count}", list.Count); + return list; + } + + public bool Create(PatientBindingModel model) + { + CheckModel(model); + if (_patientStorage.Insert(model) == null) + { + _logger.LogWarning("Insert operation failed"); + return false; + } + return true; + } + + public bool Delete(PatientBindingModel model) + { + CheckModel(model, false); + _logger.LogInformation("Delete. Id:{Id}", model.Id); + if (_patientStorage.Delete(model) == null) + { + _logger.LogWarning("Delete operation failed"); + return false; + } + return true; + } + + + public bool Update(PatientBindingModel model) + { + CheckModel(model); + if (_patientStorage.Update(model) == null) + { + _logger.LogWarning("Update operation failed"); + return false; + } + return true; + } + + private void CheckModel(PatientBindingModel 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)); + } + // TODO: проверка на наличие даты рождения и фамилии в модели? + _logger.LogInformation("Patient. Surname:{ Date}. Name: {Name}. Patronymic: {Patronymic}. BirthDate: {BirthDate}. Id: { Id}", model.Surname, model.Name, model.Patronymic, model.BirthDate, model.Id); + } + + } +} diff --git a/Hospital/HospitalBusinessLogic/PrescriptionLogic.cs b/Hospital/HospitalBusinessLogic/PrescriptionLogic.cs new file mode 100644 index 0000000..0b9d4d8 --- /dev/null +++ b/Hospital/HospitalBusinessLogic/PrescriptionLogic.cs @@ -0,0 +1,103 @@ +using HospitalContracts.BindingModels; +using HospitalContracts.BusinessLogicContracts; +using HospitalContracts.SearchModels; +using HospitalContracts.StorageContracts; +using HospitalContracts.ViewModels; +using Microsoft.Extensions.Logging; + +namespace HospitalBusinessLogic +{ + public class PrescriptionLogic : IPrescriptionLogic + { + private readonly ILogger _logger; + private readonly IPrescriptionStorage _prescriptionStorage; + + public PrescriptionLogic(ILogger logger, IPrescriptionStorage prescriptionStorage) + { + _logger = logger; + _prescriptionStorage = prescriptionStorage; + } + + public PrescriptionViewModel? ReadElement(PrescriptionSearchModel model) + { + if (model == null) + { + throw new ArgumentNullException(nameof(model)); + } + _logger.LogInformation("ReadElement. Id:{ Id}", model.Id); + var element = _prescriptionStorage.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(PrescriptionSearchModel? model) + { + _logger.LogInformation("ReadList. Id:{ Id}", model?.Id); + var list = model == null ? _prescriptionStorage.GetFullList() : _prescriptionStorage.GetFilteredList(model); + if (list == null) + { + _logger.LogWarning("ReadList return null list"); + return null; + } + _logger.LogInformation("ReadList. Count:{Count}", list.Count); + return list; + } + + public bool Create(PrescriptionBindingModel model) + { + CheckModel(model); + if (_prescriptionStorage.Insert(model) == null) + { + _logger.LogWarning("Insert operation failed"); + return false; + } + return true; + } + + public bool Delete(PrescriptionBindingModel model) + { + CheckModel(model, false); + _logger.LogInformation("Delete. Id:{Id}", model.Id); + if (_prescriptionStorage.Delete(model) == null) + { + _logger.LogWarning("Delete operation failed"); + return false; + } + return true; + } + + + public bool Update(PrescriptionBindingModel model) + { + CheckModel(model); + if (_prescriptionStorage.Update(model) == null) + { + _logger.LogWarning("Update operation failed"); + return false; + } + return true; + } + + private void CheckModel(PrescriptionBindingModel model, bool withParams = true) + { + if (model == null) + { + throw new ArgumentNullException(nameof(model)); + } + if (!withParams) + { + return; + } + if (model.Number <= 0) + { + throw new ArgumentNullException("Количество лекарств в поставке должно быть больше 0", nameof(model.Number)); + } + _logger.LogInformation("Prescription. Date:{ Date}. Number: {Number}. MedicineId: {MedicineId}. Id: { Id}", model.Date, model.Number, model.MedicineId, model.Id); + } + } +} diff --git a/Hospital/HospitalBusinessLogic/ProcedureLogic.cs b/Hospital/HospitalBusinessLogic/ProcedureLogic.cs new file mode 100644 index 0000000..a4afa2f --- /dev/null +++ b/Hospital/HospitalBusinessLogic/ProcedureLogic.cs @@ -0,0 +1,108 @@ +using HospitalContracts.BindingModels; +using HospitalContracts.BusinessLogicContracts; +using HospitalContracts.SearchModels; +using HospitalContracts.StorageContracts; +using HospitalContracts.ViewModels; +using Microsoft.Extensions.Logging; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace HospitalBusinessLogic +{ + public class ProcedureLogic : IProcedureLogic + { + private readonly ILogger _logger; + private readonly IProcedureStorage _procedureStorage; + + public ProcedureLogic(ILogger logger, IProcedureStorage procedureStorage) + { + _logger = logger; + _procedureStorage = procedureStorage; + } + public ProcedureViewModel? ReadElement(ProcedureSearchModel model) + { + if (model == null) + { + throw new ArgumentNullException(nameof(model)); + } + _logger.LogInformation("ReadElement. Id:{ Id}", 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) + { + _logger.LogInformation("ReadList. Id:{ Id}", 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 Create(ProcedureBindingModel model) + { + CheckModel(model); + if (_procedureStorage.Insert(model) == null) + { + _logger.LogWarning("Insert operation failed"); + return false; + } + return true; + } + + public bool Delete(ProcedureBindingModel model) + { + 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 bool Update(ProcedureBindingModel model) + { + 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); + } + } +} diff --git a/Hospital/HospitalBusinessLogic/RecipeLogic.cs b/Hospital/HospitalBusinessLogic/RecipeLogic.cs new file mode 100644 index 0000000..261921e --- /dev/null +++ b/Hospital/HospitalBusinessLogic/RecipeLogic.cs @@ -0,0 +1,103 @@ +using HospitalContracts.BindingModels; +using HospitalContracts.BusinessLogicContracts; +using HospitalContracts.SearchModels; +using HospitalContracts.StorageContracts; +using HospitalContracts.ViewModels; +using Microsoft.Extensions.Logging; + +namespace HospitalBusinessLogic +{ + public class RecipeLogic : IRecipeLogic + { + private readonly ILogger _logger; + private readonly IRecipeStorage _recipeStorage; + + public RecipeLogic(ILogger logger, IRecipeStorage recipeStorage) + { + _logger = logger; + _recipeStorage = recipeStorage; + } + + public RecipeViewModel? ReadElement(RecipeSearchModel model) + { + if (model == null) + { + throw new ArgumentNullException(nameof(model)); + } + _logger.LogInformation("ReadElement. Id:{ Id}", 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) + { + _logger.LogInformation("ReadList. Id:{ Id}", 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 Create(RecipeBindingModel model) + { + CheckModel(model); + if (_recipeStorage.Insert(model) == null) + { + _logger.LogWarning("Insert operation failed"); + return false; + } + return true; + } + + public bool Delete(RecipeBindingModel model) + { + CheckModel(model, false); + _logger.LogInformation("Delete. Id:{Id}", model.Id); + if (_recipeStorage.Delete(model) == null) + { + _logger.LogWarning("Delete operation failed"); + return false; + } + return true; + } + + public bool Update(RecipeBindingModel model) + { + 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 (string.IsNullOrEmpty(model.Name)) + { + throw new ArgumentNullException("Нет названия рецепта", + nameof(model.Name)); + } + _logger.LogInformation("Recipe. Date:{ Date}. Name: {Name}. Id: { Id}", model.Date, model.Name, model.Id); + } + } +} diff --git a/Hospital/HospitalBusinessLogic/TreatmentLogic.cs b/Hospital/HospitalBusinessLogic/TreatmentLogic.cs new file mode 100644 index 0000000..2358dc1 --- /dev/null +++ b/Hospital/HospitalBusinessLogic/TreatmentLogic.cs @@ -0,0 +1,104 @@ +using HospitalContracts.BindingModels; +using HospitalContracts.BusinessLogicContracts; +using HospitalContracts.SearchModels; +using HospitalContracts.StorageContracts; +using HospitalContracts.ViewModels; +using Microsoft.Extensions.Logging; + +namespace HospitalBusinessLogic +{ + public class TreatmentLogic : ITreatmentLogic + { + private readonly ILogger _logger; + private readonly ITreatmentStorage _treatmentStorage; + + public TreatmentLogic(ILogger logger, ITreatmentStorage treatmentStorage) + { + _logger = logger; + _treatmentStorage = treatmentStorage; + } + + public TreatmentViewModel? ReadElement(TreatmentSearchModel model) + { + if (model == null) + { + throw new ArgumentNullException(nameof(model)); + } + _logger.LogInformation("ReadElement. Id:{ Id}", model.Id); + var element = _treatmentStorage.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(TreatmentSearchModel? model) + { + _logger.LogInformation("ReadList. Id:{ Id}", model?.Id); + var list = model == null ? _treatmentStorage.GetFullList() : _treatmentStorage.GetFilteredList(model); + if (list == null) + { + _logger.LogWarning("ReadList return null list"); + return null; + } + _logger.LogInformation("ReadList. Count:{Count}", list.Count); + return list; + } + + public bool Create(TreatmentBindingModel model) + { + CheckModel(model); + if (_treatmentStorage.Insert(model) == null) + { + _logger.LogWarning("Insert operation failed"); + return false; + } + return true; + } + + public bool Delete(TreatmentBindingModel model) + { + CheckModel(model, false); + _logger.LogInformation("Delete. Id:{Id}", model.Id); + if (_treatmentStorage.Delete(model) == null) + { + _logger.LogWarning("Delete operation failed"); + return false; + } + return true; + } + + public bool Update(TreatmentBindingModel model) + { + CheckModel(model); + if (_treatmentStorage.Update(model) == null) + { + _logger.LogWarning("Update operation failed"); + return false; + } + return true; + } + + private void CheckModel(TreatmentBindingModel 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("Treatment. Name: {Name}.Id: { Id}", model.Name, model.Id); + } + } +} diff --git a/Hospital/HospitalWeb/HospitalWeb.csproj b/Hospital/HospitalWeb/HospitalWeb.csproj index c78c9c7..0f23fc6 100644 --- a/Hospital/HospitalWeb/HospitalWeb.csproj +++ b/Hospital/HospitalWeb/HospitalWeb.csproj @@ -6,4 +6,17 @@ enable + + + all + runtime; build; native; contentfiles; analyzers; buildtransitive + + + + + + + + +