From 1190965599391f4c1dda1d39f1b16addc626e1e0 Mon Sep 17 00:00:00 2001 From: antoc0der <1@DESKTOP-K1L8ND3> Date: Tue, 23 Apr 2024 22:32:50 +0400 Subject: [PATCH] =?UTF-8?q?=D0=BF=D0=BE=D1=80=D1=83=D1=87=D0=B8=D1=82?= =?UTF-8?q?=D0=B5=D0=BB=D1=8C=20=D0=B1=D0=B8=D0=B7=D0=BD=D0=B5=D1=81=20?= =?UTF-8?q?=D0=BB=D0=BE=D0=B3=D0=B8=D0=BA=D0=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../BusinessLogic/DoctorLogic.cs | 121 ++++++++++++++++++ .../BusinessLogic/DrugLogic.cs | 117 +++++++++++++++++ .../BusinessLogic/MedicationLogic.cs | 114 +++++++++++++++++ .../BusinessLogic/ServiceLogic.cs | 105 +++++++++++++++ .../VeterinaryBusinessLogic.csproj | 4 +- .../BindingModels/DrugBindingModel.cs | 1 + .../ViewModels/DrugViewModel.cs | 3 + .../VeterinaryDataModels/IDrugModel.cs | 1 + 8 files changed, 464 insertions(+), 2 deletions(-) create mode 100644 VeterinaryView/VeterinaryBusinessLogic/BusinessLogic/DoctorLogic.cs create mode 100644 VeterinaryView/VeterinaryBusinessLogic/BusinessLogic/DrugLogic.cs create mode 100644 VeterinaryView/VeterinaryBusinessLogic/BusinessLogic/MedicationLogic.cs create mode 100644 VeterinaryView/VeterinaryBusinessLogic/BusinessLogic/ServiceLogic.cs diff --git a/VeterinaryView/VeterinaryBusinessLogic/BusinessLogic/DoctorLogic.cs b/VeterinaryView/VeterinaryBusinessLogic/BusinessLogic/DoctorLogic.cs new file mode 100644 index 0000000..4b4a106 --- /dev/null +++ b/VeterinaryView/VeterinaryBusinessLogic/BusinessLogic/DoctorLogic.cs @@ -0,0 +1,121 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using VeterinaryContracts.BusinessLogicContracts; +using VeterinaryContracts.BindingModels; +using VeterinaryContracts.SearchModels; +using VeterinaryContracts.StorageContracts; +using VeterinaryContracts.ViewModels; +using Microsoft.Extensions.Logging; + +namespace VeterinaryBusinessLogic.BusinessLogic +{ + public class DoctorLogic : IDoctorLogic + { + private readonly ILogger _logger; + private readonly IDoctorStorage _doctorStorage; + public DoctorLogic(ILogger logger, IDoctorStorage doctorStorage) + { + _logger = logger; + _doctorStorage = doctorStorage; + } + public List? ReadList(DoctorSearchModel? model) + { + _logger.LogInformation("ReadList. DoctorFIO:{DoctorFIO}. Id:{ Id}", model?.DoctorFIO, model?.Id); + var list = model == null ? _doctorStorage.GetFullList() : _doctorStorage.GetFilteredList(model); + if (list == null) + { + _logger.LogWarning("ReadList return null list"); + return null; + } + _logger.LogInformation("ReadList. Count:{Count}", list.Count); + return list; + } + public DoctorViewModel? ReadElement(DoctorSearchModel model) + { + if (model == null) + { + throw new ArgumentNullException(nameof(model)); + } + _logger.LogInformation("ReadElement. DoctorFIO:{DoctorFIO}.Id:{ Id}", model.DoctorFIO, model.Id); + var element = _doctorStorage.GetElement(model); + if (element == null) + { + _logger.LogWarning("ReadElement element not found"); + return null; + } + _logger.LogInformation("ReadElement find. Id:{Id}", element.Id); + return element; + } + public bool Create(DoctorBindingModel model) + { + CheckModel(model); + if (_doctorStorage.Insert(model) == null) + { + _logger.LogWarning("Insert operation failed"); + return false; + } + return true; + } + public bool Update(DoctorBindingModel model) + { + CheckModel(model); + if (_doctorStorage.Update(model) == null) + { + _logger.LogWarning("Update operation failed"); + return false; + } + return true; + } + public bool Delete(DoctorBindingModel model) + { + CheckModel(model, false); + _logger.LogInformation("Delete. Id:{Id}", model.Id); + if (_doctorStorage.Delete(model) == null) + { + _logger.LogWarning("Delete operation failed"); + return false; + } + return true; + } + private void CheckModel(DoctorBindingModel model, bool withParams = + true) + { + if (model == null) + { + throw new ArgumentNullException(nameof(model)); + } + if (!withParams) + { + return; + } + if (string.IsNullOrEmpty(model.DoctorFIO)) + { + throw new ArgumentNullException("Нет ФИО доктора", + nameof(model.DoctorFIO)); + } + if (string.IsNullOrEmpty(model.Login)) + { + throw new ArgumentNullException("Нет Login доктора", + nameof(model.Login)); + } + if (string.IsNullOrEmpty(model.Password)) + { + throw new ArgumentNullException("Нет пароля доктора", + nameof(model.Password)); + } + _logger.LogInformation("Doctor. DoctorFIO:{DoctorFIO}." + + "Login:{ Login}. Password:{ Password}. Id: { Id} ", model.DoctorFIO, model.Login, model.Password, model.Id); + var element = _doctorStorage.GetElement(new DoctorSearchModel + { + Login = model.Login, + }); + if (element != null && element.Id != model.Id) + { + throw new InvalidOperationException("Доктор с таким же логином уже существует"); + } + } + } +} diff --git a/VeterinaryView/VeterinaryBusinessLogic/BusinessLogic/DrugLogic.cs b/VeterinaryView/VeterinaryBusinessLogic/BusinessLogic/DrugLogic.cs new file mode 100644 index 0000000..552f2a3 --- /dev/null +++ b/VeterinaryView/VeterinaryBusinessLogic/BusinessLogic/DrugLogic.cs @@ -0,0 +1,117 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using VeterinaryContracts.BusinessLogicContracts; +using VeterinaryContracts.BindingModels; +using VeterinaryContracts.SearchModels; +using VeterinaryContracts.StorageContracts; +using VeterinaryContracts.ViewModels; +using Microsoft.Extensions.Logging; + + +namespace VeterinaryBusinessLogic.BusinessLogic +{ + public class DrugLogic : IDrugLogic + { + private readonly ILogger _logger; + private readonly IDrugStorage _drugStorage; + public DrugLogic(ILogger logger, IDrugStorage drugStorage) + { + _logger = logger; + _drugStorage = drugStorage; + } + public List? ReadList(DrugSearchModel? model) + { + _logger.LogInformation("ReadList. DrugName:{DrugName}.Id:{ Id}", model?.DrugName, model?.Id); + var list = model == null ? _drugStorage.GetFullList() : _drugStorage.GetFilteredList(model); + if (list == null) + { + _logger.LogWarning("ReadList return null list"); + return null; + } + _logger.LogInformation("ReadList. Count:{Count}", list.Count); + return list; + } + public DrugViewModel? ReadElement(DrugSearchModel model) + { + if (model == null) + { + throw new ArgumentNullException(nameof(model)); + } + _logger.LogInformation("ReadElement. DrugName:{DrugName}.Id:{ Id}", model.DrugName, model.Id); + var element = _drugStorage.GetElement(model); + if (element == null) + { + _logger.LogWarning("ReadElement element not found"); + return null; + } + _logger.LogInformation("ReadElement find. Id:{Id}", element.Id); + return element; + } + public bool Create(DrugBindingModel model) + { + CheckModel(model); + if (_drugStorage.Insert(model) == null) + { + _logger.LogWarning("Insert operation failed"); + return false; + } + return true; + } + public bool Update(DrugBindingModel model) + { + CheckModel(model); + if (_drugStorage.Update(model) == null) + { + _logger.LogWarning("Update operation failed"); + return false; + } + return true; + } + public bool Delete(DrugBindingModel model) + { + CheckModel(model, false); + _logger.LogInformation("Delete. Id:{Id}", model.Id); + if (_drugStorage.Delete(model) == null) + { + _logger.LogWarning("Delete operation failed"); + return false; + } + return true; + } + private void CheckModel(DrugBindingModel model, bool withParams = true) + { + if (model == null) + { + throw new ArgumentNullException(nameof(model)); + } + if (!withParams) + { + return; + } + if (string.IsNullOrEmpty(model.DrugName)) + { + throw new ArgumentNullException("Нет названия лекарства", nameof(model.DrugName)); + } + if (model.Count <= 0) + { + throw new ArgumentNullException("Лекарств должно быть больше нуля", nameof(model.Count)); + } + if (model.Price <= 0) + { + throw new ArgumentNullException("Цена лекарства должна быть больше 0", nameof(model.Price)); + } + _logger.LogInformation("Drug. DrugName:{DrugName}.Count:{ Count}.Price:{ Price}. Id: { Id}", model.DrugName,model.Count, model.Price, model.Id); + var element = _drugStorage.GetElement(new DrugSearchModel + { + DrugName = model.DrugName + }); + if (element != null && element.Id != model.Id) + { + throw new InvalidOperationException("Лекарство с таким названием уже есть"); + } + } + } +} diff --git a/VeterinaryView/VeterinaryBusinessLogic/BusinessLogic/MedicationLogic.cs b/VeterinaryView/VeterinaryBusinessLogic/BusinessLogic/MedicationLogic.cs new file mode 100644 index 0000000..e0b4288 --- /dev/null +++ b/VeterinaryView/VeterinaryBusinessLogic/BusinessLogic/MedicationLogic.cs @@ -0,0 +1,114 @@ +using Microsoft.Extensions.Logging; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using VeterinaryContracts.BusinessLogicContracts; +using VeterinaryContracts.BindingModels; +using VeterinaryContracts.SearchModels; +using VeterinaryContracts.StorageContracts; +using VeterinaryContracts.ViewModels; + + +namespace VeterinaryBusinessLogic.BusinessLogic +{ + public class MedicationLogic : IMedicationLogic + { + private readonly ILogger _logger; + private readonly IMedicationStorage _medicationStorage; + public MedicationLogic(ILogger logger, IMedicationStorage medicationStorage) + { + _logger = logger; + _medicationStorage = medicationStorage; + } + public List? ReadList(MedicationSearchModel? model) + { + _logger.LogInformation("ReadList. MedicationName:{MedicationName}.Id:{ Id}", model?.MedicationName, model?.Id); + var list = model == null ? _medicationStorage.GetFullList() : _medicationStorage.GetFilteredList(model); + if (list == null) + { + _logger.LogWarning("ReadList return null list"); + return null; + } + _logger.LogInformation("ReadList. Count:{Count}", list.Count); + return list; + } + public MedicationViewModel? ReadElement(MedicationSearchModel model) + { + if (model == null) + { + throw new ArgumentNullException(nameof(model)); + } + _logger.LogInformation("ReadElement. MedicationName:{MedicationName}.Id:{ Id}", model.MedicationName, model.Id); + var element = _medicationStorage.GetElement(model); + if (element == null) + { + _logger.LogWarning("ReadElement element not found"); + return null; + } + _logger.LogInformation("ReadElement find. Id:{Id}", element.Id); + return element; + } + public bool Create(MedicationBindingModel model) + { + CheckModel(model); + if (_medicationStorage.Insert(model) == null) + { + _logger.LogWarning("Insert operation failed"); + return false; + } + return true; + } + public bool Update(MedicationBindingModel model) + { + CheckModel(model); + if (_medicationStorage.Update(model) == null) + { + _logger.LogWarning("Update operation failed"); + return false; + } + return true; + } + public bool Delete(MedicationBindingModel model) + { + CheckModel(model, false); + _logger.LogInformation("Delete. Id:{Id}", model.Id); + if (_medicationStorage.Delete(model) == null) + { + _logger.LogWarning("Delete operation failed"); + return false; + } + return true; + } + private void CheckModel(MedicationBindingModel model, bool withParams = true) + { + if (model == null) + { + throw new ArgumentNullException(nameof(model)); + } + if (!withParams) + { + return; + } + if (string.IsNullOrEmpty(model.MedicationName)) + { + throw new ArgumentNullException("Нет названия медикамента", + nameof(model.MedicationName)); + } + if (model.Price <= 0) + { + throw new ArgumentNullException("Цена медикамента должна быть больше 0", nameof(model.Price)); + } + _logger.LogInformation("Medication. MedicationName:{MedicationName}.Price:{ Price}. Id: { Id}", model.MedicationName, model.Price, model.Id); + var element = _medicationStorage.GetElement(new MedicationSearchModel + { + MedicationName = model.MedicationName + }); + if (element != null && element.Id != model.Id) + { + throw new InvalidOperationException("Медикамент с таким названием уже есть"); + } + } + } +} diff --git a/VeterinaryView/VeterinaryBusinessLogic/BusinessLogic/ServiceLogic.cs b/VeterinaryView/VeterinaryBusinessLogic/BusinessLogic/ServiceLogic.cs new file mode 100644 index 0000000..f441850 --- /dev/null +++ b/VeterinaryView/VeterinaryBusinessLogic/BusinessLogic/ServiceLogic.cs @@ -0,0 +1,105 @@ +using Microsoft.Extensions.Logging; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using VeterinaryContracts.BusinessLogicContracts; +using VeterinaryContracts.BindingModels; +using VeterinaryContracts.SearchModels; +using VeterinaryContracts.StorageContracts; +using VeterinaryContracts.ViewModels; + +namespace VeterinaryBusinessLogic.BusinessLogic +{ + public class ServiceLogic : IServiceLogic + { + private readonly ILogger _logger; + private readonly IServiceStorage _serviceStorage; + public ServiceLogic(ILogger logger, IServiceStorage serviceStorage) + { + _logger = logger; + _serviceStorage = serviceStorage; + } + public List? ReadList(ServiceSearchModel? model) + { + _logger.LogInformation("ReadList. ServiceName:{ServiceName}.Id:{ Id}", model?.ServiceName, model?.Id); + var list = model == null ? _serviceStorage.GetFullList() : _serviceStorage.GetFilteredList(model); + if (list == null) + { + _logger.LogWarning("ReadList return null list"); + return null; + } + _logger.LogInformation("ReadList. Count:{Count}", list.Count); + return list; + } + public ServiceViewModel? ReadElement(ServiceSearchModel model) + { + if (model == null) + { + throw new ArgumentNullException(nameof(model)); + } + _logger.LogInformation("ReadElement. ServiceName:{ServiceName}.Id:{ Id}", model.ServiceName, model.Id); + var element = _serviceStorage.GetElement(model); + if (element == null) + { + _logger.LogWarning("ReadElement element not found"); + return null; + } + _logger.LogInformation("ReadElement find. Id:{Id}", element.Id); + return element; + } + public bool Create(ServiceBindingModel model) + { + CheckModel(model); + if (_serviceStorage.Insert(model) == null) + { + _logger.LogWarning("Insert operation failed"); + return false; + } + return true; + } + public bool Update(ServiceBindingModel model) + { + CheckModel(model); + if (_serviceStorage.Update(model) == null) + { + _logger.LogWarning("Update operation failed"); + return false; + } + return true; + } + public bool Delete(ServiceBindingModel model) + { + CheckModel(model, false); + _logger.LogInformation("Delete. Id:{Id}", model.Id); + if (_serviceStorage.Delete(model) == null) + { + _logger.LogWarning("Delete operation failed"); + return false; + } + return true; + } + private void CheckModel(ServiceBindingModel model, bool withParams = true) + { + if (model == null) + { + throw new ArgumentNullException(nameof(model)); + } + if (!withParams) + { + return; + } + if (string.IsNullOrEmpty(model.ServiceName)) + { + throw new ArgumentNullException("Нет названия услуги", nameof(model.ServiceName)); + } + _logger.LogInformation("Service. ServiceName:{ServiceName} Id: { Id}", model.ServiceName, model.Id); + var element = _serviceStorage.GetElement(new ServiceSearchModel + { + ServiceName = model.ServiceName + }); + + } + } +} diff --git a/VeterinaryView/VeterinaryBusinessLogic/VeterinaryBusinessLogic.csproj b/VeterinaryView/VeterinaryBusinessLogic/VeterinaryBusinessLogic.csproj index 400377b..3110a4b 100644 --- a/VeterinaryView/VeterinaryBusinessLogic/VeterinaryBusinessLogic.csproj +++ b/VeterinaryView/VeterinaryBusinessLogic/VeterinaryBusinessLogic.csproj @@ -7,11 +7,11 @@ - + - + diff --git a/VeterinaryView/VeterinaryContracts/BindingModels/DrugBindingModel.cs b/VeterinaryView/VeterinaryContracts/BindingModels/DrugBindingModel.cs index 6c6ac86..a955aa0 100644 --- a/VeterinaryView/VeterinaryContracts/BindingModels/DrugBindingModel.cs +++ b/VeterinaryView/VeterinaryContracts/BindingModels/DrugBindingModel.cs @@ -12,6 +12,7 @@ namespace VeterinaryContracts.BindingModels public int Id { get; set; } public string DrugName { get; set; } = string.Empty; public int Count { get; set; } + public double Price { get; set; } public Dictionary DrugMedications { get; diff --git a/VeterinaryView/VeterinaryContracts/ViewModels/DrugViewModel.cs b/VeterinaryView/VeterinaryContracts/ViewModels/DrugViewModel.cs index 3e5ad0d..7970b42 100644 --- a/VeterinaryView/VeterinaryContracts/ViewModels/DrugViewModel.cs +++ b/VeterinaryView/VeterinaryContracts/ViewModels/DrugViewModel.cs @@ -15,6 +15,9 @@ namespace VeterinaryContracts.ViewModels public string DrugName { get; set; } = string.Empty; [DisplayName("Количество")] public int Count { get; set; } + [DisplayName("Цена лекарства")] + public double Price { get; set; } + public Dictionary DrugMedications { get; diff --git a/VeterinaryView/VeterinaryDataModels/IDrugModel.cs b/VeterinaryView/VeterinaryDataModels/IDrugModel.cs index 7206ae8..db46b81 100644 --- a/VeterinaryView/VeterinaryDataModels/IDrugModel.cs +++ b/VeterinaryView/VeterinaryDataModels/IDrugModel.cs @@ -10,6 +10,7 @@ namespace VeterinaryDataModels { string DrugName { get; } int Count { get; } + double Price { get; } Dictionary DrugMedications { get; } } }