BusinessLogics
This commit is contained in:
parent
f573848354
commit
4257dea204
@ -7,7 +7,9 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "HospitalDataModels", "Hospi
|
||||
EndProject
|
||||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "HospitalContracts", "HospitalContracts\HospitalContracts.csproj", "{435124E0-E0A5-4EB8-A46C-C093C47A65F7}"
|
||||
EndProject
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "HospitalDatabaseImplement", "HospitalDatabaseImplement\HospitalDatabaseImplement.csproj", "{595F63B0-79FF-4EBA-9582-2A0652D00B58}"
|
||||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "HospitalDatabaseImplement", "HospitalDatabaseImplement\HospitalDatabaseImplement.csproj", "{595F63B0-79FF-4EBA-9582-2A0652D00B58}"
|
||||
EndProject
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "HospitalBusinessLogics", "HospitalBusinessLogics\HospitalBusinessLogics.csproj", "{1A20292D-5690-4C8A-859E-9CC72F0AACB5}"
|
||||
EndProject
|
||||
Global
|
||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||
@ -27,6 +29,10 @@ Global
|
||||
{595F63B0-79FF-4EBA-9582-2A0652D00B58}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{595F63B0-79FF-4EBA-9582-2A0652D00B58}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{595F63B0-79FF-4EBA-9582-2A0652D00B58}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
{1A20292D-5690-4C8A-859E-9CC72F0AACB5}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{1A20292D-5690-4C8A-859E-9CC72F0AACB5}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{1A20292D-5690-4C8A-859E-9CC72F0AACB5}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{1A20292D-5690-4C8A-859E-9CC72F0AACB5}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
EndGlobalSection
|
||||
GlobalSection(SolutionProperties) = preSolution
|
||||
HideSolutionNode = FALSE
|
||||
|
179
Hospital/HospitalBusinessLogics/BusinessLogics/DiseaseLogic.cs
Normal file
179
Hospital/HospitalBusinessLogics/BusinessLogics/DiseaseLogic.cs
Normal file
@ -0,0 +1,179 @@
|
||||
using HospitalContracts.BindingModels;
|
||||
using HospitalContracts.BusinessLogicsContracts;
|
||||
using HospitalContracts.SearchModels;
|
||||
using HospitalContracts.StoragesContracts;
|
||||
using HospitalContracts.ViewModels;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace HospitalBusinessLogics.BusinessLogics
|
||||
{
|
||||
/// <summary>
|
||||
/// Бизнес-логика для сущности "Болезнь"
|
||||
/// </summary>
|
||||
public class DiseaseLogic : IDiseaseLogic
|
||||
{
|
||||
/// <summary>
|
||||
/// Логгер
|
||||
/// </summary>
|
||||
private readonly ILogger _logger;
|
||||
|
||||
/// <summary>
|
||||
/// Хранилище
|
||||
/// </summary>
|
||||
private readonly IDiseaseStorage _diseaseStorage;
|
||||
|
||||
/// <summary>
|
||||
/// Конструктор
|
||||
/// </summary>
|
||||
/// <param name="logger"></param>
|
||||
/// <param name="diseaseStorage"></param>
|
||||
public DiseaseLogic(ILogger<DiseaseLogic> logger, IDiseaseStorage diseaseStorage)
|
||||
{
|
||||
_logger = logger;
|
||||
_diseaseStorage = diseaseStorage;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Получить список
|
||||
/// </summary>
|
||||
/// <param name="model"></param>
|
||||
/// <returns></returns>
|
||||
public List<DiseaseViewModel>? ReadList(DiseaseSearchModel? model)
|
||||
{
|
||||
_logger.LogInformation("ReadList. Disease.Id: {Id}. RecipeId: {RecipeId}. Name: {Name}", model?.Id, model?.RecipeId, model?.Name);
|
||||
|
||||
var list = model == null ? _diseaseStorage.GetFullList() : _diseaseStorage.GetFilteredList(model);
|
||||
if (list == null)
|
||||
{
|
||||
_logger.LogWarning("ReadList. Returned null list");
|
||||
return null;
|
||||
}
|
||||
|
||||
_logger.LogInformation("ReadList. Count: {Count}", list.Count);
|
||||
return list;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Получить отдельную запись
|
||||
/// </summary>
|
||||
/// <param name="model"></param>
|
||||
/// <returns></returns>
|
||||
/// <exception cref="ArgumentNullException"></exception>
|
||||
public DiseaseViewModel? ReadElement(DiseaseSearchModel model)
|
||||
{
|
||||
if (model == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(model));
|
||||
}
|
||||
|
||||
_logger.LogInformation("ReadElement. Disease.Id: {Id}. Name: {Name}", model?.Id, model?.Name);
|
||||
|
||||
var element = _diseaseStorage.GetElement(model!);
|
||||
if (element == null)
|
||||
{
|
||||
_logger.LogWarning("ReadElement. Element not found");
|
||||
return null;
|
||||
}
|
||||
|
||||
_logger.LogInformation("ReadElement. Find Disease.Id: {Id}", element?.Id);
|
||||
return element;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Создать запись
|
||||
/// </summary>
|
||||
/// <param name="model"></param>
|
||||
/// <returns></returns>
|
||||
public bool Create(DiseaseBindingModel model)
|
||||
{
|
||||
CheckModel(model);
|
||||
_logger.LogInformation("Create. Disease.Id: {Id}", model.Id);
|
||||
|
||||
if (_diseaseStorage.Insert(model) == null)
|
||||
{
|
||||
_logger.LogWarning("Insert operation failed");
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Изменить запись
|
||||
/// </summary>
|
||||
/// <param name="model"></param>
|
||||
/// <returns></returns>
|
||||
public bool Update(DiseaseBindingModel model)
|
||||
{
|
||||
CheckModel(model);
|
||||
_logger.LogInformation("Update. Disease.Id: {Id}", model.Id);
|
||||
|
||||
if (_diseaseStorage.Update(model) == null)
|
||||
{
|
||||
_logger.LogWarning("Update operation failed");
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Удалить запись
|
||||
/// </summary>
|
||||
/// <param name="model"></param>
|
||||
/// <returns></returns>
|
||||
public bool Delete(DiseaseBindingModel model)
|
||||
{
|
||||
CheckModel(model, false);
|
||||
_logger.LogInformation("Delete. Disease.Id: {Id}", model.Id);
|
||||
|
||||
if (_diseaseStorage.Delete(model) == null)
|
||||
{
|
||||
_logger.LogWarning("Delete operation failed");
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Проверка модели
|
||||
/// </summary>
|
||||
/// <param name="model"></param>
|
||||
/// <param name="withParams"></param>
|
||||
/// <exception cref="ArgumentNullException"></exception>
|
||||
/// <exception cref="InvalidOperationException"></exception>
|
||||
private void CheckModel(DiseaseBindingModel 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.RecipeId <= 0)
|
||||
{
|
||||
throw new ArgumentNullException("Не указан идентификатор рецепта", nameof(model.RecipeId));
|
||||
}
|
||||
|
||||
_logger.LogInformation("CheckModel. Disease.Id: {Id}", model.Id);
|
||||
|
||||
var element = _diseaseStorage.GetElement(new DiseaseSearchModel
|
||||
{
|
||||
Name = model.Name
|
||||
});
|
||||
if (element != null && !element.Id.Equals(model.Id))
|
||||
{
|
||||
throw new InvalidOperationException("Болезнь с таким названием уже существует");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
183
Hospital/HospitalBusinessLogics/BusinessLogics/DoctorLogic.cs
Normal file
183
Hospital/HospitalBusinessLogics/BusinessLogics/DoctorLogic.cs
Normal file
@ -0,0 +1,183 @@
|
||||
using HospitalContracts.BindingModels;
|
||||
using HospitalContracts.BusinessLogicsContracts;
|
||||
using HospitalContracts.SearchModels;
|
||||
using HospitalContracts.StoragesContracts;
|
||||
using HospitalContracts.ViewModels;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace HospitalBusinessLogics.BusinessLogics
|
||||
{
|
||||
/// <summary>
|
||||
/// Бизнес-логика для сущности "Доктор"
|
||||
/// </summary>
|
||||
public class DoctorLogic : IDoctorLogic
|
||||
{
|
||||
/// <summary>
|
||||
/// Логгер
|
||||
/// </summary>
|
||||
private readonly ILogger _logger;
|
||||
|
||||
/// <summary>
|
||||
/// Хранилище
|
||||
/// </summary>
|
||||
private readonly IDoctorStorage _doctorStorage;
|
||||
|
||||
/// <summary>
|
||||
/// Конструктор
|
||||
/// </summary>
|
||||
/// <param name="logger"></param>
|
||||
/// <param name="doctorStorage"></param>
|
||||
public DoctorLogic(ILogger<DoctorLogic> logger, IDoctorStorage doctorStorage)
|
||||
{
|
||||
_logger = logger;
|
||||
_doctorStorage = doctorStorage;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Получить список
|
||||
/// </summary>
|
||||
/// <param name="model"></param>
|
||||
/// <returns></returns>
|
||||
public List<DoctorViewModel>? ReadList(DoctorSearchModel? model)
|
||||
{
|
||||
_logger.LogInformation("ReadList. Doctor.Id: {Id}. Email: {Email}. FullName: {FullName}", model?.Id, model?.Email, model?.FullName);
|
||||
|
||||
var list = model == null ? _doctorStorage.GetFullList() : _doctorStorage.GetFilteredList(model);
|
||||
if (list == null)
|
||||
{
|
||||
_logger.LogWarning("ReadList. Returned null list");
|
||||
return null;
|
||||
}
|
||||
|
||||
_logger.LogInformation("ReadList. Count: {Count}", list.Count);
|
||||
return list;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Получить отдельную запись
|
||||
/// </summary>
|
||||
/// <param name="model"></param>
|
||||
/// <returns></returns>
|
||||
/// <exception cref="ArgumentNullException"></exception>
|
||||
public DoctorViewModel? ReadElement(DoctorSearchModel model)
|
||||
{
|
||||
if (model == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(model));
|
||||
}
|
||||
|
||||
_logger.LogInformation("ReadElement. Doctor.Id: {Id}. Email: {Email}. Password: {Password}", model?.Id, model?.Email, model?.Password);
|
||||
|
||||
var element = _doctorStorage.GetElement(model!);
|
||||
if (element == null)
|
||||
{
|
||||
_logger.LogWarning("ReadElement. Element not found");
|
||||
return null;
|
||||
}
|
||||
|
||||
_logger.LogInformation("ReadElement. Find Doctor.Id: {Id}", element?.Id);
|
||||
return element;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Создать запись
|
||||
/// </summary>
|
||||
/// <param name="model"></param>
|
||||
/// <returns></returns>
|
||||
public bool Create(DoctorBindingModel model)
|
||||
{
|
||||
CheckModel(model);
|
||||
_logger.LogInformation("Create. Doctor.Id: {Id}", model.Id);
|
||||
|
||||
if (_doctorStorage.Insert(model) == null)
|
||||
{
|
||||
_logger.LogWarning("Insert operation failed");
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Изменить запись
|
||||
/// </summary>
|
||||
/// <param name="model"></param>
|
||||
/// <returns></returns>
|
||||
public bool Update(DoctorBindingModel model)
|
||||
{
|
||||
CheckModel(model);
|
||||
_logger.LogInformation("Update. Doctor.Id: {Id}", model.Id);
|
||||
|
||||
if (_doctorStorage.Update(model) == null)
|
||||
{
|
||||
_logger.LogWarning("Update operation failed");
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Удалить запись
|
||||
/// </summary>
|
||||
/// <param name="model"></param>
|
||||
/// <returns></returns>
|
||||
public bool Delete(DoctorBindingModel model)
|
||||
{
|
||||
CheckModel(model, false);
|
||||
_logger.LogInformation("Delete. Doctor.Id: {Id}", model.Id);
|
||||
|
||||
if (_doctorStorage.Delete(model) == null)
|
||||
{
|
||||
_logger.LogWarning("Delete operation failed");
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Проверка модели
|
||||
/// </summary>
|
||||
/// <param name="model"></param>
|
||||
/// <param name="withParams"></param>
|
||||
/// <exception cref="ArgumentNullException"></exception>
|
||||
/// <exception cref="InvalidOperationException"></exception>
|
||||
private void CheckModel(DoctorBindingModel model, bool withParams = true)
|
||||
{
|
||||
if (model == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(model));
|
||||
}
|
||||
if (!withParams)
|
||||
{
|
||||
return;
|
||||
}
|
||||
if (string.IsNullOrEmpty(model.FullName))
|
||||
{
|
||||
throw new ArgumentNullException("Не указано ФИО доктора", nameof(model.FullName));
|
||||
}
|
||||
if (string.IsNullOrEmpty(model.Email))
|
||||
{
|
||||
throw new ArgumentNullException("Не указана электронная почта (логин)", nameof(model.Email));
|
||||
}
|
||||
if (string.IsNullOrEmpty(model.Password))
|
||||
{
|
||||
throw new ArgumentNullException("Не указан пароль", nameof(model.Password));
|
||||
}
|
||||
|
||||
_logger.LogInformation("CheckModel. Doctor.Id: {Id}", model.Id);
|
||||
|
||||
var element = _doctorStorage.GetElement(new DoctorSearchModel
|
||||
{
|
||||
Email = model.Email
|
||||
});
|
||||
if (element != null && !element.Id.Equals(model.Id))
|
||||
{
|
||||
throw new InvalidOperationException("Доктор с такой электронной почтой (логином) уже существует");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
175
Hospital/HospitalBusinessLogics/BusinessLogics/MedicineLogic.cs
Normal file
175
Hospital/HospitalBusinessLogics/BusinessLogics/MedicineLogic.cs
Normal file
@ -0,0 +1,175 @@
|
||||
using HospitalContracts.BindingModels;
|
||||
using HospitalContracts.BusinessLogicsContracts;
|
||||
using HospitalContracts.SearchModels;
|
||||
using HospitalContracts.StoragesContracts;
|
||||
using HospitalContracts.ViewModels;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace HospitalBusinessLogics.BusinessLogics
|
||||
{
|
||||
/// <summary>
|
||||
/// Бизнес-логика для сущности "Лекарство"
|
||||
/// </summary>
|
||||
public class MedicineLogic : IMedicineLogic
|
||||
{
|
||||
/// <summary>
|
||||
/// Логгер
|
||||
/// </summary>
|
||||
private readonly ILogger _logger;
|
||||
|
||||
/// <summary>
|
||||
/// Хранилище
|
||||
/// </summary>
|
||||
private readonly IMedicineStorage _medicineStorage;
|
||||
|
||||
/// <summary>
|
||||
/// Конструктор
|
||||
/// </summary>
|
||||
/// <param name="logger"></param>
|
||||
/// <param name="medicineStorage"></param>
|
||||
public MedicineLogic(ILogger<MedicineLogic> logger, IMedicineStorage medicineStorage)
|
||||
{
|
||||
_logger = logger;
|
||||
_medicineStorage = medicineStorage;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Получить список
|
||||
/// </summary>
|
||||
/// <param name="model"></param>
|
||||
/// <returns></returns>
|
||||
public List<MedicineViewModel>? ReadList(MedicineSearchModel? model)
|
||||
{
|
||||
_logger.LogInformation("ReadList. Medicine.Id: {Id}. Name: {Name}", model?.Id, model?.Name);
|
||||
|
||||
var list = model == null ? _medicineStorage.GetFullList() : _medicineStorage.GetFilteredList(model);
|
||||
if (list == null)
|
||||
{
|
||||
_logger.LogWarning("ReadList. Returned null list");
|
||||
return null;
|
||||
}
|
||||
|
||||
_logger.LogInformation("ReadList. Count: {Count}", list.Count);
|
||||
return list;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Получить отдельную запись
|
||||
/// </summary>
|
||||
/// <param name="model"></param>
|
||||
/// <returns></returns>
|
||||
/// <exception cref="ArgumentNullException"></exception>
|
||||
public MedicineViewModel? ReadElement(MedicineSearchModel model)
|
||||
{
|
||||
if (model == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(model));
|
||||
}
|
||||
|
||||
_logger.LogInformation("ReadElement. Medicine.Id: {Id}. Name: {Name}", model?.Id, model?.Name);
|
||||
|
||||
var element = _medicineStorage.GetElement(model!);
|
||||
if (element == null)
|
||||
{
|
||||
_logger.LogWarning("ReadElement. Element not found");
|
||||
return null;
|
||||
}
|
||||
|
||||
_logger.LogInformation("ReadElement. Find Medicine.Id: {Id}", element?.Id);
|
||||
return element;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Создать запись
|
||||
/// </summary>
|
||||
/// <param name="model"></param>
|
||||
/// <returns></returns>
|
||||
public bool Create(MedicineBindingModel model)
|
||||
{
|
||||
CheckModel(model);
|
||||
_logger.LogInformation("Create. Medicine.Id: {Id}", model.Id);
|
||||
|
||||
if (_medicineStorage.Insert(model) == null)
|
||||
{
|
||||
_logger.LogWarning("Insert operation failed");
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Изменить запись
|
||||
/// </summary>
|
||||
/// <param name="model"></param>
|
||||
/// <returns></returns>
|
||||
public bool Update(MedicineBindingModel model)
|
||||
{
|
||||
CheckModel(model);
|
||||
_logger.LogInformation("Update. Medicine.Id: {Id}", model.Id);
|
||||
|
||||
if (_medicineStorage.Update(model) == null)
|
||||
{
|
||||
_logger.LogWarning("Update operation failed");
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Удалить запись
|
||||
/// </summary>
|
||||
/// <param name="model"></param>
|
||||
/// <returns></returns>
|
||||
public bool Delete(MedicineBindingModel model)
|
||||
{
|
||||
CheckModel(model, false);
|
||||
_logger.LogInformation("Delete. Medicine.Id: {Id}", model.Id);
|
||||
|
||||
if (_medicineStorage.Delete(model) == null)
|
||||
{
|
||||
_logger.LogWarning("Delete operation failed");
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Проверка модели
|
||||
/// </summary>
|
||||
/// <param name="model"></param>
|
||||
/// <param name="withParams"></param>
|
||||
/// <exception cref="ArgumentNullException"></exception>
|
||||
/// <exception cref="InvalidOperationException"></exception>
|
||||
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));
|
||||
}
|
||||
|
||||
_logger.LogInformation("CheckModel. Medicine.Id: {Id}", model.Id);
|
||||
|
||||
var element = _medicineStorage.GetElement(new MedicineSearchModel
|
||||
{
|
||||
Name = model.Name
|
||||
});
|
||||
if (element != null && !element.Id.Equals(model.Id))
|
||||
{
|
||||
throw new InvalidOperationException("Лекарство с таким названием уже существует");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
187
Hospital/HospitalBusinessLogics/BusinessLogics/PatientLogic.cs
Normal file
187
Hospital/HospitalBusinessLogics/BusinessLogics/PatientLogic.cs
Normal file
@ -0,0 +1,187 @@
|
||||
using HospitalContracts.BindingModels;
|
||||
using HospitalContracts.BusinessLogicsContracts;
|
||||
using HospitalContracts.SearchModels;
|
||||
using HospitalContracts.StoragesContracts;
|
||||
using HospitalContracts.ViewModels;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace HospitalBusinessLogics.BusinessLogics
|
||||
{
|
||||
/// <summary>
|
||||
/// Бизнес-логика для сущности "Пациент"
|
||||
/// </summary>
|
||||
public class PatientLogic : IPatientLogic
|
||||
{
|
||||
/// <summary>
|
||||
/// Логгер
|
||||
/// </summary>
|
||||
private readonly ILogger _logger;
|
||||
|
||||
/// <summary>
|
||||
/// Хранилище
|
||||
/// </summary>
|
||||
private readonly IPatientStorage _patientStorage;
|
||||
|
||||
/// <summary>
|
||||
/// Конструктор
|
||||
/// </summary>
|
||||
/// <param name="logger"></param>
|
||||
/// <param name="patientStorage"></param>
|
||||
public PatientLogic(ILogger<PatientLogic> logger, IPatientStorage patientStorage)
|
||||
{
|
||||
_logger = logger;
|
||||
_patientStorage = patientStorage;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Получить список
|
||||
/// </summary>
|
||||
/// <param name="model"></param>
|
||||
/// <returns></returns>
|
||||
public List<PatientViewModel>? ReadList(PatientSearchModel? model)
|
||||
{
|
||||
_logger.LogInformation("ReadList. Patient.Id: {Id}. DoctorId: {DoctorId}. FullName: {FullName}", model?.Id, model?.DoctorId, model?.FullName);
|
||||
|
||||
var list = model == null ? _patientStorage.GetFullList() : _patientStorage.GetFilteredList(model);
|
||||
if (list == null)
|
||||
{
|
||||
_logger.LogWarning("ReadList. Returned null list");
|
||||
return null;
|
||||
}
|
||||
|
||||
_logger.LogInformation("ReadList. Count: {Count}", list.Count);
|
||||
return list;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Получить отдельную запись
|
||||
/// </summary>
|
||||
/// <param name="model"></param>
|
||||
/// <returns></returns>
|
||||
/// <exception cref="ArgumentNullException"></exception>
|
||||
public PatientViewModel? ReadElement(PatientSearchModel model)
|
||||
{
|
||||
if (model == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(model));
|
||||
}
|
||||
|
||||
_logger.LogInformation("ReadElement. Patient.Id: {Id}. Phone: {Phone}", model?.Id, model?.Phone);
|
||||
|
||||
var element = _patientStorage.GetElement(model!);
|
||||
if (element == null)
|
||||
{
|
||||
_logger.LogWarning("ReadElement. Element not found");
|
||||
return null;
|
||||
}
|
||||
|
||||
_logger.LogInformation("ReadElement. Find Patient.Id: {Id}", element?.Id);
|
||||
return element;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Создать запись
|
||||
/// </summary>
|
||||
/// <param name="model"></param>
|
||||
/// <returns></returns>
|
||||
public bool Create(PatientBindingModel model)
|
||||
{
|
||||
CheckModel(model);
|
||||
_logger.LogInformation("Create. Patient.Id: {Id}", model.Id);
|
||||
|
||||
if (_patientStorage.Insert(model) == null)
|
||||
{
|
||||
_logger.LogWarning("Insert operation failed");
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Изменить запись
|
||||
/// </summary>
|
||||
/// <param name="model"></param>
|
||||
/// <returns></returns>
|
||||
public bool Update(PatientBindingModel model)
|
||||
{
|
||||
CheckModel(model);
|
||||
_logger.LogInformation("Update. Patient.Id: {Id}", model.Id);
|
||||
|
||||
if (_patientStorage.Update(model) == null)
|
||||
{
|
||||
_logger.LogWarning("Update operation failed");
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Удалить запись
|
||||
/// </summary>
|
||||
/// <param name="model"></param>
|
||||
/// <returns></returns>
|
||||
public bool Delete(PatientBindingModel model)
|
||||
{
|
||||
CheckModel(model, false);
|
||||
_logger.LogInformation("Delete. Patient.Id: {Id}", model.Id);
|
||||
|
||||
if (_patientStorage.Delete(model) == null)
|
||||
{
|
||||
_logger.LogWarning("Delete operation failed");
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Проверка модели
|
||||
/// </summary>
|
||||
/// <param name="model"></param>
|
||||
/// <param name="withParams"></param>
|
||||
/// <exception cref="ArgumentNullException"></exception>
|
||||
/// <exception cref="InvalidOperationException"></exception>
|
||||
private void CheckModel(PatientBindingModel model, bool withParams = true)
|
||||
{
|
||||
if (model == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(model));
|
||||
}
|
||||
if (!withParams)
|
||||
{
|
||||
return;
|
||||
}
|
||||
if (string.IsNullOrEmpty(model.FullName))
|
||||
{
|
||||
throw new ArgumentNullException("Не указано ФИО пациента", nameof(model.FullName));
|
||||
}
|
||||
if (model.BirthDate == DateTime.MinValue)
|
||||
{
|
||||
throw new ArgumentNullException("Не указана дата рождения пациента", nameof(model.BirthDate));
|
||||
}
|
||||
if (string.IsNullOrEmpty(model.Phone))
|
||||
{
|
||||
throw new ArgumentNullException("Не указан номер телефона", nameof(model.Phone));
|
||||
}
|
||||
if (model.DoctorId <= 0)
|
||||
{
|
||||
throw new ArgumentNullException("Не указан идентификатор лечащего врача", nameof(model.DoctorId));
|
||||
}
|
||||
|
||||
_logger.LogInformation("CheckModel. Patient.Id: {Id}", model.Id);
|
||||
|
||||
var element = _patientStorage.GetElement(new PatientSearchModel
|
||||
{
|
||||
Phone = model.Phone
|
||||
});
|
||||
if (element != null && !element.Id.Equals(model.Id))
|
||||
{
|
||||
throw new InvalidOperationException("Пациент с таким номером телефона уже существует");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
175
Hospital/HospitalBusinessLogics/BusinessLogics/ProcedureLogic.cs
Normal file
175
Hospital/HospitalBusinessLogics/BusinessLogics/ProcedureLogic.cs
Normal file
@ -0,0 +1,175 @@
|
||||
using HospitalContracts.BindingModels;
|
||||
using HospitalContracts.BusinessLogicsContracts;
|
||||
using HospitalContracts.SearchModels;
|
||||
using HospitalContracts.StoragesContracts;
|
||||
using HospitalContracts.ViewModels;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace HospitalBusinessLogics.BusinessLogics
|
||||
{
|
||||
/// <summary>
|
||||
/// Бизнес-логика для сущности "Процедура"
|
||||
/// </summary>
|
||||
public class ProcedureLogic : IProcedureLogic
|
||||
{
|
||||
/// <summary>
|
||||
/// Логгер
|
||||
/// </summary>
|
||||
private readonly ILogger _logger;
|
||||
|
||||
/// <summary>
|
||||
/// Хранилище
|
||||
/// </summary>
|
||||
private readonly IProcedureStorage _procedureStorage;
|
||||
|
||||
/// <summary>
|
||||
/// Конструктор
|
||||
/// </summary>
|
||||
/// <param name="logger"></param>
|
||||
/// <param name="procedureStorage"></param>
|
||||
public ProcedureLogic(ILogger<ProcedureLogic> logger, IProcedureStorage procedureStorage)
|
||||
{
|
||||
_logger = logger;
|
||||
_procedureStorage = procedureStorage;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Получить список
|
||||
/// </summary>
|
||||
/// <param name="model"></param>
|
||||
/// <returns></returns>
|
||||
public List<ProcedureViewModel>? ReadList(ProcedureSearchModel? model)
|
||||
{
|
||||
_logger.LogInformation("ReadList. Procedure.Id: {Id}. Name: {Name}", model?.Id, model?.Name);
|
||||
|
||||
var list = model == null ? _procedureStorage.GetFullList() : _procedureStorage.GetFilteredList(model);
|
||||
if (list == null)
|
||||
{
|
||||
_logger.LogWarning("ReadList. Returned null list");
|
||||
return null;
|
||||
}
|
||||
|
||||
_logger.LogInformation("ReadList. Count: {Count}", list.Count);
|
||||
return list;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Получить отдельную запись
|
||||
/// </summary>
|
||||
/// <param name="model"></param>
|
||||
/// <returns></returns>
|
||||
/// <exception cref="ArgumentNullException"></exception>
|
||||
public ProcedureViewModel? ReadElement(ProcedureSearchModel model)
|
||||
{
|
||||
if (model == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(model));
|
||||
}
|
||||
|
||||
_logger.LogInformation("ReadElement. Procedure.Id: {Id}. Name: {Name}", model?.Id, model?.Name);
|
||||
|
||||
var element = _procedureStorage.GetElement(model!);
|
||||
if (element == null)
|
||||
{
|
||||
_logger.LogWarning("ReadElement. Element not found");
|
||||
return null;
|
||||
}
|
||||
|
||||
_logger.LogInformation("ReadElement. Find Procedure.Id: {Id}", element?.Id);
|
||||
return element;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Создать запись
|
||||
/// </summary>
|
||||
/// <param name="model"></param>
|
||||
/// <returns></returns>
|
||||
public bool Create(ProcedureBindingModel model)
|
||||
{
|
||||
CheckModel(model);
|
||||
_logger.LogInformation("Create. Procedure.Id: {Id}", model.Id);
|
||||
|
||||
if (_procedureStorage.Insert(model) == null)
|
||||
{
|
||||
_logger.LogWarning("Insert operation failed");
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Изменить запись
|
||||
/// </summary>
|
||||
/// <param name="model"></param>
|
||||
/// <returns></returns>
|
||||
public bool Update(ProcedureBindingModel model)
|
||||
{
|
||||
CheckModel(model);
|
||||
_logger.LogInformation("Update. Procedure.Id: {Id}", model.Id);
|
||||
|
||||
if (_procedureStorage.Update(model) == null)
|
||||
{
|
||||
_logger.LogWarning("Update operation failed");
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Удалить запись
|
||||
/// </summary>
|
||||
/// <param name="model"></param>
|
||||
/// <returns></returns>
|
||||
public bool Delete(ProcedureBindingModel model)
|
||||
{
|
||||
CheckModel(model, false);
|
||||
_logger.LogInformation("Delete. Procedure.Id: {Id}", model.Id);
|
||||
|
||||
if (_procedureStorage.Delete(model) == null)
|
||||
{
|
||||
_logger.LogWarning("Delete operation failed");
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Проверка модели
|
||||
/// </summary>
|
||||
/// <param name="model"></param>
|
||||
/// <param name="withParams"></param>
|
||||
/// <exception cref="ArgumentNullException"></exception>
|
||||
/// <exception cref="InvalidOperationException"></exception>
|
||||
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("CheckModel. Procedure.Id: {Id}", model.Id);
|
||||
|
||||
var element = _procedureStorage.GetElement(new ProcedureSearchModel
|
||||
{
|
||||
Name = model.Name
|
||||
});
|
||||
if (element != null && !element.Id.Equals(model.Id))
|
||||
{
|
||||
throw new InvalidOperationException("Процедура с таким названием уже существует");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
170
Hospital/HospitalBusinessLogics/BusinessLogics/RecipeLogic.cs
Normal file
170
Hospital/HospitalBusinessLogics/BusinessLogics/RecipeLogic.cs
Normal file
@ -0,0 +1,170 @@
|
||||
using HospitalContracts.BindingModels;
|
||||
using HospitalContracts.BusinessLogicsContracts;
|
||||
using HospitalContracts.SearchModels;
|
||||
using HospitalContracts.StoragesContracts;
|
||||
using HospitalContracts.ViewModels;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace HospitalBusinessLogics.BusinessLogics
|
||||
{
|
||||
/// <summary>
|
||||
/// Бизнес-логика для сущности "Рецепт"
|
||||
/// </summary>
|
||||
public class RecipeLogic : IRecipeLogic
|
||||
{
|
||||
/// <summary>
|
||||
/// Логгер
|
||||
/// </summary>
|
||||
private readonly ILogger _logger;
|
||||
|
||||
/// <summary>
|
||||
/// Хранилище
|
||||
/// </summary>
|
||||
private readonly IRecipeStorage _recipeStorage;
|
||||
|
||||
/// <summary>
|
||||
/// Конструктор
|
||||
/// </summary>
|
||||
/// <param name="logger"></param>
|
||||
/// <param name="recipeStorage"></param>
|
||||
public RecipeLogic(ILogger<RecipeLogic> logger, IRecipeStorage recipeStorage)
|
||||
{
|
||||
_logger = logger;
|
||||
_recipeStorage = recipeStorage;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Получить список
|
||||
/// </summary>
|
||||
/// <param name="model"></param>
|
||||
/// <returns></returns>
|
||||
public List<RecipeViewModel>? ReadList(RecipeSearchModel? model)
|
||||
{
|
||||
_logger.LogInformation("ReadList. Recipe.Id: {Id}. DoctorId: {DoctorId}", model?.Id, model?.DoctorId);
|
||||
|
||||
var list = model == null ? _recipeStorage.GetFullList() : _recipeStorage.GetFilteredList(model);
|
||||
if (list == null)
|
||||
{
|
||||
_logger.LogWarning("ReadList. Returned null list");
|
||||
return null;
|
||||
}
|
||||
|
||||
_logger.LogInformation("ReadList. Count: {Count}", list.Count);
|
||||
return list;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Получить отдельную запись
|
||||
/// </summary>
|
||||
/// <param name="model"></param>
|
||||
/// <returns></returns>
|
||||
/// <exception cref="ArgumentNullException"></exception>
|
||||
public RecipeViewModel? ReadElement(RecipeSearchModel model)
|
||||
{
|
||||
if (model == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(model));
|
||||
}
|
||||
|
||||
_logger.LogInformation("ReadElement. Recipe.Id: {Id}", model?.Id);
|
||||
|
||||
var element = _recipeStorage.GetElement(model!);
|
||||
if (element == null)
|
||||
{
|
||||
_logger.LogWarning("ReadElement. Element not found");
|
||||
return null;
|
||||
}
|
||||
|
||||
_logger.LogInformation("ReadElement. Find Recipe.Id: {Id}", element?.Id);
|
||||
return element;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Создать запись
|
||||
/// </summary>
|
||||
/// <param name="model"></param>
|
||||
/// <returns></returns>
|
||||
public bool Create(RecipeBindingModel model)
|
||||
{
|
||||
CheckModel(model);
|
||||
_logger.LogInformation("Create. Recipe.Id: {Id}", model.Id);
|
||||
|
||||
if (_recipeStorage.Insert(model) == null)
|
||||
{
|
||||
_logger.LogWarning("Insert operation failed");
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Изменить запись
|
||||
/// </summary>
|
||||
/// <param name="model"></param>
|
||||
/// <returns></returns>
|
||||
public bool Update(RecipeBindingModel model)
|
||||
{
|
||||
CheckModel(model);
|
||||
_logger.LogInformation("Update. Recipe.Id: {Id}", model.Id);
|
||||
|
||||
if (_recipeStorage.Update(model) == null)
|
||||
{
|
||||
_logger.LogWarning("Update operation failed");
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Удалить запись
|
||||
/// </summary>
|
||||
/// <param name="model"></param>
|
||||
/// <returns></returns>
|
||||
public bool Delete(RecipeBindingModel model)
|
||||
{
|
||||
CheckModel(model, false);
|
||||
_logger.LogInformation("Delete. Recipe.Id: {Id}", model.Id);
|
||||
|
||||
if (_recipeStorage.Delete(model) == null)
|
||||
{
|
||||
_logger.LogWarning("Delete operation failed");
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Проверка модели
|
||||
/// </summary>
|
||||
/// <param name="model"></param>
|
||||
/// <param name="withParams"></param>
|
||||
/// <exception cref="ArgumentNullException"></exception>
|
||||
/// <exception cref="InvalidOperationException"></exception>
|
||||
private void CheckModel(RecipeBindingModel model, bool withParams = true)
|
||||
{
|
||||
if (model == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(model));
|
||||
}
|
||||
if (!withParams)
|
||||
{
|
||||
return;
|
||||
}
|
||||
if (model.IssueDate == DateTime.MinValue)
|
||||
{
|
||||
throw new ArgumentNullException("Не указана дата выписки рецепта", nameof(model.IssueDate));
|
||||
}
|
||||
if (model.DoctorId <= 0)
|
||||
{
|
||||
throw new ArgumentNullException("Не указан идентификатор доктора", nameof(model.DoctorId));
|
||||
}
|
||||
|
||||
_logger.LogInformation("CheckModel. Recipe.Id: {Id}", model.Id);
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,17 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>net6.0</TargetFramework>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<Nullable>enable</Nullable>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Microsoft.Extensions.Logging" Version="8.0.0" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\HospitalContracts\HospitalContracts.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
@ -12,7 +12,7 @@ namespace HospitalContracts.StoragesContracts
|
||||
/// <summary>
|
||||
/// Интерфейс для описания работы с хранилищем для сущности "Процедура"
|
||||
/// </summary>
|
||||
public interface IProcedureStrorage
|
||||
public interface IProcedureStorage
|
||||
{
|
||||
/// <summary>
|
||||
/// Получить полный список
|
@ -16,7 +16,7 @@ namespace HospitalDatabaseImplement.Implements
|
||||
/// <summary>
|
||||
/// Хранилище для сущности "Процедура"
|
||||
/// </summary>
|
||||
public class ProcedureStorage : IProcedureStrorage
|
||||
public class ProcedureStorage : IProcedureStorage
|
||||
{
|
||||
/// <summary>
|
||||
/// Получить полный список
|
||||
|
Loading…
Reference in New Issue
Block a user