Исправление: комментарии и убраны неиспользующиеся методы бизнес-логики
This commit is contained in:
parent
86f949cc30
commit
abd474d67d
@ -1,111 +0,0 @@
|
||||
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<PatientLogic> 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<PatientViewModel>? 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));
|
||||
}
|
||||
|
||||
_logger.LogInformation("Patient. Surname:{ Date}. Name: {Name}. Patronymic: {Patronymic}. BirthDate: {BirthDate}. Id: { Id}", model.Surname, model.Name, model.Patronymic, model.BirthDate, model.Id);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
@ -52,28 +52,6 @@ namespace HospitalBusinessLogic
|
||||
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)
|
||||
{
|
||||
|
@ -47,58 +47,5 @@ namespace HospitalBusinessLogic
|
||||
_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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,15 +0,0 @@
|
||||
using HospitalContracts.BindingModels;
|
||||
using HospitalContracts.SearchModels;
|
||||
using HospitalContracts.ViewModels;
|
||||
|
||||
namespace HospitalContracts.BusinessLogicContracts
|
||||
{
|
||||
public interface IPatientLogic
|
||||
{
|
||||
List<PatientViewModel>? ReadList(PatientSearchModel? model);
|
||||
PatientViewModel? ReadElement(PatientSearchModel model);
|
||||
bool Create(PatientBindingModel model);
|
||||
bool Update(PatientBindingModel model);
|
||||
bool Delete(PatientBindingModel model);
|
||||
}
|
||||
}
|
@ -4,12 +4,10 @@ using HospitalContracts.ViewModels;
|
||||
|
||||
namespace HospitalContracts.BusinessLogicContracts
|
||||
{
|
||||
public interface IProcedureLogic
|
||||
public interface IProcedureLogic // потребуется чтение записей и обновление (для привязки лекарств)
|
||||
{
|
||||
List<ProcedureViewModel>? ReadList(ProcedureSearchModel? model);
|
||||
ProcedureViewModel? ReadElement(ProcedureSearchModel model);
|
||||
bool Create(ProcedureBindingModel model);
|
||||
bool Update(ProcedureBindingModel model);
|
||||
bool Delete(ProcedureBindingModel model);
|
||||
}
|
||||
}
|
||||
|
@ -4,12 +4,9 @@ using HospitalContracts.ViewModels;
|
||||
|
||||
namespace HospitalContracts.BusinessLogicContracts
|
||||
{
|
||||
public interface ITreatmentLogic
|
||||
public interface ITreatmentLogic // потребуется только чтение (для привязки рецептов к выбранным лечениям)
|
||||
{
|
||||
List<TreatmentViewModel>? ReadList(TreatmentSearchModel? model);
|
||||
TreatmentViewModel? ReadElement(TreatmentSearchModel model);
|
||||
bool Create(TreatmentBindingModel model);
|
||||
bool Update(TreatmentBindingModel model);
|
||||
bool Delete(TreatmentBindingModel model);
|
||||
}
|
||||
}
|
||||
|
@ -21,7 +21,6 @@ namespace HospitalDatabaseImplement.Implements
|
||||
?.GetViewModel;
|
||||
}
|
||||
|
||||
// TODO подумать над параметрами фильтрации
|
||||
public List<ApothecaryViewModel> GetFilteredList(ApothecarySearchModel model)
|
||||
{
|
||||
if (string.IsNullOrEmpty(model.Login) || string.IsNullOrEmpty(model.Password))
|
||||
|
@ -21,7 +21,7 @@ namespace HospitalDatabaseImplement
|
||||
/// Чтение пациентов из XML-файла
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public static void LoadPatients()
|
||||
public static void LoadPatients() // (запуск после загрузки лечений)
|
||||
{
|
||||
using var context = new HospitalDatabase();
|
||||
if (context.Patients.ToList().Count > 0)
|
||||
@ -35,10 +35,10 @@ namespace HospitalDatabaseImplement
|
||||
|
||||
}
|
||||
/// <summary>
|
||||
/// Чтение лечений из XML-файла
|
||||
/// Чтение лечений из XML-файла
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public static void LoadTreatments()
|
||||
public static void LoadTreatments() // (запуск после загрузки процедур)
|
||||
{
|
||||
using var context = new HospitalDatabase();
|
||||
if (context.Treatments.ToList().Count > 0)
|
||||
@ -51,10 +51,10 @@ namespace HospitalDatabaseImplement
|
||||
context.SaveChanges();
|
||||
}
|
||||
/// <summary>
|
||||
/// Чтение поцедур из XML-файла
|
||||
/// Чтение поцедур из XML-файла
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public static void LoadProcedures()
|
||||
public static void LoadProcedures()// (запуск после старта программы)
|
||||
{
|
||||
using var context = new HospitalDatabase();
|
||||
if (context.Procedures.ToList().Count > 0)
|
||||
@ -62,10 +62,9 @@ namespace HospitalDatabaseImplement
|
||||
var list = LoadData(ProcedureFileName, "Procedure", x => Procedure.Create(x)!)!;
|
||||
list.ForEach(x =>
|
||||
{
|
||||
context.Procedures.Add(x);
|
||||
context.SaveChanges();
|
||||
context.Procedures.Add(x);
|
||||
});
|
||||
|
||||
context.SaveChanges();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user