diff --git a/Hospital/HospitalBusinessLogic/PatientLogic.cs b/Hospital/HospitalBusinessLogic/PatientLogic.cs deleted file mode 100644 index bea9da4..0000000 --- a/Hospital/HospitalBusinessLogic/PatientLogic.cs +++ /dev/null @@ -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 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)); - } - - _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/ProcedureLogic.cs b/Hospital/HospitalBusinessLogic/ProcedureLogic.cs index a4afa2f..efe59a8 100644 --- a/Hospital/HospitalBusinessLogic/ProcedureLogic.cs +++ b/Hospital/HospitalBusinessLogic/ProcedureLogic.cs @@ -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) { diff --git a/Hospital/HospitalBusinessLogic/TreatmentLogic.cs b/Hospital/HospitalBusinessLogic/TreatmentLogic.cs index 2358dc1..67db00a 100644 --- a/Hospital/HospitalBusinessLogic/TreatmentLogic.cs +++ b/Hospital/HospitalBusinessLogic/TreatmentLogic.cs @@ -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); - } } } diff --git a/Hospital/HospitalContracts/BusinessLogicContracts/IPatientLogic.cs b/Hospital/HospitalContracts/BusinessLogicContracts/IPatientLogic.cs deleted file mode 100644 index 3cdcd28..0000000 --- a/Hospital/HospitalContracts/BusinessLogicContracts/IPatientLogic.cs +++ /dev/null @@ -1,15 +0,0 @@ -using HospitalContracts.BindingModels; -using HospitalContracts.SearchModels; -using HospitalContracts.ViewModels; - -namespace HospitalContracts.BusinessLogicContracts -{ - public interface IPatientLogic - { - List? ReadList(PatientSearchModel? model); - PatientViewModel? ReadElement(PatientSearchModel model); - bool Create(PatientBindingModel model); - bool Update(PatientBindingModel model); - bool Delete(PatientBindingModel model); - } -} diff --git a/Hospital/HospitalContracts/BusinessLogicContracts/IProcedureLogic.cs b/Hospital/HospitalContracts/BusinessLogicContracts/IProcedureLogic.cs index 2248d32..bffdf01 100644 --- a/Hospital/HospitalContracts/BusinessLogicContracts/IProcedureLogic.cs +++ b/Hospital/HospitalContracts/BusinessLogicContracts/IProcedureLogic.cs @@ -4,12 +4,10 @@ using HospitalContracts.ViewModels; namespace HospitalContracts.BusinessLogicContracts { - public interface IProcedureLogic + public interface IProcedureLogic // потребуется чтение записей и обновление (для привязки лекарств) { List? ReadList(ProcedureSearchModel? model); ProcedureViewModel? ReadElement(ProcedureSearchModel model); - bool Create(ProcedureBindingModel model); bool Update(ProcedureBindingModel model); - bool Delete(ProcedureBindingModel model); } } diff --git a/Hospital/HospitalContracts/BusinessLogicContracts/ITreatmentLogic.cs b/Hospital/HospitalContracts/BusinessLogicContracts/ITreatmentLogic.cs index 1a6fca1..77bd474 100644 --- a/Hospital/HospitalContracts/BusinessLogicContracts/ITreatmentLogic.cs +++ b/Hospital/HospitalContracts/BusinessLogicContracts/ITreatmentLogic.cs @@ -4,12 +4,9 @@ using HospitalContracts.ViewModels; namespace HospitalContracts.BusinessLogicContracts { - public interface ITreatmentLogic + public interface ITreatmentLogic // потребуется только чтение (для привязки рецептов к выбранным лечениям) { List? ReadList(TreatmentSearchModel? model); TreatmentViewModel? ReadElement(TreatmentSearchModel model); - bool Create(TreatmentBindingModel model); - bool Update(TreatmentBindingModel model); - bool Delete(TreatmentBindingModel model); } } diff --git a/Hospital/HospitalDatabaseImplement/Implements/ApothecaryStorage.cs b/Hospital/HospitalDatabaseImplement/Implements/ApothecaryStorage.cs index a286c15..f2bd179 100644 --- a/Hospital/HospitalDatabaseImplement/Implements/ApothecaryStorage.cs +++ b/Hospital/HospitalDatabaseImplement/Implements/ApothecaryStorage.cs @@ -21,7 +21,6 @@ namespace HospitalDatabaseImplement.Implements ?.GetViewModel; } - // TODO подумать над параметрами фильтрации public List GetFilteredList(ApothecarySearchModel model) { if (string.IsNullOrEmpty(model.Login) || string.IsNullOrEmpty(model.Password)) diff --git a/Hospital/HospitalDatabaseImplement/LoaderFromXML.cs b/Hospital/HospitalDatabaseImplement/LoaderFromXML.cs index 4986cbc..5a8ca82 100644 --- a/Hospital/HospitalDatabaseImplement/LoaderFromXML.cs +++ b/Hospital/HospitalDatabaseImplement/LoaderFromXML.cs @@ -21,7 +21,7 @@ namespace HospitalDatabaseImplement /// Чтение пациентов из XML-файла /// /// - 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 } /// - /// Чтение лечений из XML-файла + /// Чтение лечений из XML-файла /// /// - 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(); } /// - /// Чтение поцедур из XML-файла + /// Чтение поцедур из XML-файла /// /// - 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(); } } }