Добавление начальной миграции #5
@ -3,13 +3,15 @@ Microsoft Visual Studio Solution File, Format Version 12.00
|
||||
# Visual Studio Version 17
|
||||
VisualStudioVersion = 17.9.34714.143
|
||||
MinimumVisualStudioVersion = 10.0.40219.1
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "PolyclinicView", "PolyclinicView\PolyclinicView.csproj", "{D45F3F15-39D7-416B-882F-517D479E8BBC}"
|
||||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "PolyclinicView", "PolyclinicView\PolyclinicView.csproj", "{D45F3F15-39D7-416B-882F-517D479E8BBC}"
|
||||
EndProject
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "PolyclinicDataModels", "PolyclinicDataModels\PolyclinicDataModels.csproj", "{4270CD59-76A0-4011-8A30-284FE5F75C26}"
|
||||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "PolyclinicDataModels", "PolyclinicDataModels\PolyclinicDataModels.csproj", "{4270CD59-76A0-4011-8A30-284FE5F75C26}"
|
||||
EndProject
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "PolyclinicContracts", "PolyclinicContracts\PolyclinicContracts.csproj", "{83EF9483-CD78-4C56-9848-C0A8325FEB41}"
|
||||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "PolyclinicContracts", "PolyclinicContracts\PolyclinicContracts.csproj", "{83EF9483-CD78-4C56-9848-C0A8325FEB41}"
|
||||
EndProject
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "PolyclinicDatabaseImplement", "PolyclinicDatabaseImplement\PolyclinicDatabaseImplement.csproj", "{E1C0ECAB-93C0-4364-B920-456F2CAA31C5}"
|
||||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "PolyclinicDatabaseImplement", "PolyclinicDatabaseImplement\PolyclinicDatabaseImplement.csproj", "{E1C0ECAB-93C0-4364-B920-456F2CAA31C5}"
|
||||
EndProject
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "PolyclinicBusinessLogic", "PolyclinicBusinessLogic\PolyclinicBusinessLogic.csproj", "{E3BCC45F-09E7-4E60-A662-8FAB01B25885}"
|
||||
EndProject
|
||||
Global
|
||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||
@ -33,6 +35,10 @@ Global
|
||||
{E1C0ECAB-93C0-4364-B920-456F2CAA31C5}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{E1C0ECAB-93C0-4364-B920-456F2CAA31C5}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{E1C0ECAB-93C0-4364-B920-456F2CAA31C5}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
{E3BCC45F-09E7-4E60-A662-8FAB01B25885}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{E3BCC45F-09E7-4E60-A662-8FAB01B25885}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{E3BCC45F-09E7-4E60-A662-8FAB01B25885}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{E3BCC45F-09E7-4E60-A662-8FAB01B25885}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
EndGlobalSection
|
||||
GlobalSection(SolutionProperties) = preSolution
|
||||
HideSolutionNode = FALSE
|
||||
|
105
Polyclinic/PolyclinicBusinessLogic/BusinessLogics/CourseLogic.cs
Normal file
105
Polyclinic/PolyclinicBusinessLogic/BusinessLogics/CourseLogic.cs
Normal file
@ -0,0 +1,105 @@
|
||||
using Microsoft.Extensions.Logging;
|
||||
using PolyclinicContracts.BindingModels;
|
||||
using PolyclinicContracts.BusinessLogicsContracts;
|
||||
using PolyclinicContracts.SearchModels;
|
||||
using PolyclinicContracts.StoragesContracts;
|
||||
using PolyclinicContracts.ViewModels;
|
||||
|
||||
namespace PolyclinicBusinessLogic.BusinessLogics
|
||||
{
|
||||
public class CourseLogic : ICourseLogic
|
||||
{
|
||||
private ILogger _logger;
|
||||
private ICourseStorage _courseStorage;
|
||||
|
||||
public CourseLogic(ILogger logger, ICourseStorage courseStorage)
|
||||
{
|
||||
_logger = logger;
|
||||
_courseStorage = courseStorage;
|
||||
}
|
||||
|
||||
public bool Create(CourseBindingModel model)
|
||||
{
|
||||
CheckModel(model);
|
||||
if (_courseStorage.Insert(model) == null)
|
||||
{
|
||||
_logger.LogWarning("Insert operation failed");
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public bool Delete(CourseBindingModel model)
|
||||
{
|
||||
CheckModel(model, false);
|
||||
_logger.LogInformation("Delete. Id:{Id}", model.Id);
|
||||
if (_courseStorage.Delete(model) == null)
|
||||
{
|
||||
_logger.LogWarning("Delete operation failed");
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public CourseViewModel? ReadElement(CourseSearchModel model)
|
||||
{
|
||||
if (model == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(model));
|
||||
}
|
||||
_logger.LogInformation("ReadElement. Id:{Id}", model.Id);
|
||||
var element = _courseStorage.GetElement(model);
|
||||
if (element == null)
|
||||
{
|
||||
_logger.LogWarning("ReadElement element not found");
|
||||
return null;
|
||||
}
|
||||
_logger.LogInformation("ReadElement. Id:{Id}", element.Id);
|
||||
return element;
|
||||
}
|
||||
|
||||
public List<CourseViewModel>? ReadList(CourseSearchModel? model)
|
||||
{
|
||||
_logger.LogInformation("ReadList. Id:{Id}", model?.Id);
|
||||
var list = model == null ? _courseStorage.GetFullList() : _courseStorage.GetFilteredList(model);
|
||||
if (list == null)
|
||||
{
|
||||
_logger.LogWarning("ReadList return null list");
|
||||
return null;
|
||||
}
|
||||
_logger.LogInformation("ReadList. Count:{Count}", list.Count);
|
||||
return list;
|
||||
}
|
||||
|
||||
public bool Update(CourseBindingModel model)
|
||||
{
|
||||
CheckModel(model);
|
||||
if (_courseStorage.Update(model) == null)
|
||||
{
|
||||
_logger.LogWarning("Update operation failed");
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
private void CheckModel(CourseBindingModel model, bool withParams = true)
|
||||
{
|
||||
if (model == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(model));
|
||||
}
|
||||
if (!withParams)
|
||||
{
|
||||
return;
|
||||
}
|
||||
if (model.DaysCount < 1)
|
||||
{
|
||||
throw new ArgumentNullException("Количество дней приема должно быть больше нуля", nameof(model.DaysCount));
|
||||
}
|
||||
if (model.PillsPerDay < 1)
|
||||
{
|
||||
throw new ArgumentNullException("Количество препарата в день должно быть больше нуля", nameof(model.PillsPerDay));
|
||||
}
|
||||
_logger.LogInformation("Course. Id: {Id}", model.Id);
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,109 @@
|
||||
using Microsoft.Extensions.Logging;
|
||||
using PolyclinicContracts.BindingModels;
|
||||
using PolyclinicContracts.BusinessLogicsContracts;
|
||||
using PolyclinicContracts.SearchModels;
|
||||
using PolyclinicContracts.StoragesContracts;
|
||||
using PolyclinicContracts.ViewModels;
|
||||
|
||||
namespace PolyclinicBusinessLogic.BusinessLogics
|
||||
{
|
||||
public class DiagnoseLogic : IDiagnoseLogic
|
||||
{
|
||||
private ILogger _logger;
|
||||
private IDiagnoseStorage _diagnoseStorage;
|
||||
|
||||
public DiagnoseLogic(ILogger logger, IDiagnoseStorage diagnoseStorage)
|
||||
{
|
||||
_logger = logger;
|
||||
_diagnoseStorage = diagnoseStorage;
|
||||
}
|
||||
|
||||
public bool Create(DiagnoseBindingModel model)
|
||||
{
|
||||
CheckModel(model);
|
||||
if (_diagnoseStorage.Insert(model) == null)
|
||||
{
|
||||
_logger.LogWarning("Insert operation failed");
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public bool Delete(DiagnoseBindingModel model)
|
||||
{
|
||||
CheckModel(model, false);
|
||||
_logger.LogInformation("Delete. Name:{Name}, Id:{Id}", model.Name, model.Id);
|
||||
if (_diagnoseStorage.Delete(model) == null)
|
||||
{
|
||||
_logger.LogWarning("Delete operation failed");
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public DiagnoseViewModel? ReadElement(DiagnoseSearchModel model)
|
||||
{
|
||||
if (model == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(model));
|
||||
}
|
||||
_logger.LogInformation("ReadElement. Name:{Name}, Id:{Id}, UserId:{UserId}", model.Name, model.Id, model.UserId);
|
||||
var element = _diagnoseStorage.GetElement(model);
|
||||
if (element == null)
|
||||
{
|
||||
_logger.LogWarning("ReadElement element not found");
|
||||
return null;
|
||||
}
|
||||
_logger.LogInformation("ReadElement find. Name:{Name}, Id:{Id}, UserId:{UserId}", element.Name, element.Id, element.UserId);
|
||||
return element;
|
||||
}
|
||||
|
||||
public List<DiagnoseViewModel>? ReadList(DiagnoseSearchModel? model)
|
||||
{
|
||||
_logger.LogInformation("ReadList. Name:{Name} Id:{Id}, UserId:{UserId}", model?.Name, model?.Id, model?.UserId);
|
||||
var list = model == null ? _diagnoseStorage.GetFullList() : _diagnoseStorage.GetFilteredList(model);
|
||||
if (list == null)
|
||||
{
|
||||
_logger.LogWarning("ReadList return null list");
|
||||
return null;
|
||||
}
|
||||
_logger.LogInformation("ReadList. Count:{Count}", list.Count);
|
||||
return list;
|
||||
}
|
||||
|
||||
public bool Update(DiagnoseBindingModel model)
|
||||
{
|
||||
CheckModel(model);
|
||||
if (_diagnoseStorage.Update(model) == null)
|
||||
{
|
||||
_logger.LogWarning("Update operation failed");
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
private void CheckModel(DiagnoseBindingModel 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("Diagnose. Name:{Name}. Id: {Id}", model.Name, model.Id);
|
||||
var element = _diagnoseStorage.GetElement(new DiagnoseSearchModel
|
||||
{
|
||||
Name = model.Name
|
||||
});
|
||||
if (element != null && element.Id != model.Id)
|
||||
{
|
||||
throw new InvalidOperationException("Болезнь с таким названием уже есть");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,124 @@
|
||||
using Microsoft.Extensions.Logging;
|
||||
using PolyclinicContracts.BindingModels;
|
||||
using PolyclinicContracts.BusinessLogicsContracts;
|
||||
using PolyclinicContracts.SearchModels;
|
||||
using PolyclinicContracts.StoragesContracts;
|
||||
using PolyclinicContracts.ViewModels;
|
||||
|
||||
namespace PolyclinicBusinessLogic.BusinessLogics
|
||||
{
|
||||
public class MedicamentLogic : IMedicamentLogic
|
||||
{
|
||||
private readonly ILogger logger;
|
||||
private readonly IMedicamentStorage medicamentStorage;
|
||||
|
||||
public MedicamentLogic(ILogger<MedicamentLogic> logger, IMedicamentStorage medicamentStorage)
|
||||
{
|
||||
this.logger = logger;
|
||||
this.medicamentStorage = medicamentStorage;
|
||||
}
|
||||
public bool Create(MedicamentBindingModel model)
|
||||
{
|
||||
CheckModel(model);
|
||||
if(medicamentStorage.Insert(model) == null)
|
||||
{
|
||||
logger.LogWarning("Create operation failed");
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public bool Delete(MedicamentBindingModel model)
|
||||
{
|
||||
CheckModel(model, false);
|
||||
if (medicamentStorage.Delete(model) == null)
|
||||
{
|
||||
logger.LogWarning("Delete operation failed");
|
||||
return false;
|
||||
}
|
||||
logger.LogInformation("Delete. Id:{Id}", model.Id);
|
||||
return true;
|
||||
}
|
||||
|
||||
public MedicamentViewModel? ReadElement(MedicamentSearchModel model)
|
||||
{
|
||||
if (model == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(model));
|
||||
}
|
||||
logger.LogInformation("ReadElement. MedicamentName:{Name}.Id:{ Id}", model.Name, model.Id);
|
||||
var element = medicamentStorage.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<MedicamentViewModel>? ReadList(MedicamentSearchModel? model)
|
||||
{
|
||||
logger.LogInformation("ReadList. Name:{Name}. Id:{ Id}", model?.Name, model?.Id);
|
||||
var list = model == null ? medicamentStorage.GetFullList() : medicamentStorage.GetFilteredList(model);
|
||||
if (list == null)
|
||||
{
|
||||
logger.LogWarning("ReadList return null list");
|
||||
return null;
|
||||
}
|
||||
logger.LogInformation("ReadList. Count:{Count}", list.Count);
|
||||
return list;
|
||||
}
|
||||
|
||||
public bool Update(MedicamentBindingModel model)
|
||||
{
|
||||
CheckModel(model);
|
||||
if (medicamentStorage.Update(model) == null)
|
||||
{
|
||||
logger.LogWarning("Update operation failed");
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
private void CheckModel(MedicamentBindingModel model, bool withParams = true)
|
||||
{
|
||||
if (model == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(model));
|
||||
}
|
||||
if (!withParams)
|
||||
{
|
||||
return;
|
||||
}
|
||||
if (model.SymptomId <= 0)
|
||||
{
|
||||
throw new ArgumentNullException("Какой-то неправильный идентификатор симптома...", nameof(model));
|
||||
}
|
||||
if (model.ProcedureId <= 0)
|
||||
{
|
||||
throw new ArgumentNullException("Какой-то неправильный идентификатор процедуры...", nameof(model));
|
||||
}
|
||||
if (string.IsNullOrEmpty(model.Comment))
|
||||
{
|
||||
throw new ArgumentNullException("Нет комментария", nameof(model.Comment));
|
||||
}
|
||||
if (string.IsNullOrEmpty(model.Name))
|
||||
{
|
||||
throw new ArgumentNullException("Нет названия у препарата", nameof(model.Comment));
|
||||
}
|
||||
|
||||
var element = medicamentStorage.GetElement(new MedicamentSearchModel
|
||||
{
|
||||
Name = model.Name
|
||||
});
|
||||
|
||||
if (element != null && element.Id != model.Id)
|
||||
{
|
||||
throw new InvalidOperationException("Препарат с таким названием уже есть");
|
||||
}
|
||||
|
||||
logger.LogInformation("Medicament. Comment:{Comment}. Id: { Id}", model.Comment, model.Id);
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,113 @@
|
||||
using Microsoft.Extensions.Logging;
|
||||
using PolyclinicContracts.BindingModels;
|
||||
using PolyclinicContracts.BusinessLogicsContracts;
|
||||
using PolyclinicContracts.SearchModels;
|
||||
using PolyclinicContracts.StoragesContracts;
|
||||
using PolyclinicContracts.ViewModels;
|
||||
|
||||
namespace PolyclinicBusinessLogic.BusinessLogics
|
||||
{
|
||||
public class ProcedureLogic : IProcedureLogic
|
||||
{
|
||||
|
||||
private readonly ILogger logger;
|
||||
private readonly IProcedureStorage procedureStorage;
|
||||
|
||||
public ProcedureLogic(ILogger<ProcedureLogic> logger, IProcedureStorage procedureStorage)
|
||||
{
|
||||
this.logger = logger;
|
||||
this.procedureStorage = procedureStorage;
|
||||
}
|
||||
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 ProcedureViewModel? ReadElement(ProcedureSearchModel model)
|
||||
{
|
||||
if (model == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(model));
|
||||
}
|
||||
logger.LogInformation("ReadElement. ProcedureName:{ProcedureName}.Id:{ Id}", model.Name, 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<ProcedureViewModel>? ReadList(ProcedureSearchModel? model)
|
||||
{
|
||||
logger.LogInformation("ReadList. Name:{Name}. Id:{ Id}", model?.Name, 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 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);
|
||||
|
||||
var element = procedureStorage.GetElement(new ProcedureSearchModel
|
||||
{
|
||||
Name = model.Name
|
||||
});
|
||||
|
||||
if (element != null && element.Id != model.Id)
|
||||
{
|
||||
throw new InvalidOperationException("Процедура с таким названием уже есть");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
106
Polyclinic/PolyclinicBusinessLogic/BusinessLogics/RecipeLogic.cs
Normal file
106
Polyclinic/PolyclinicBusinessLogic/BusinessLogics/RecipeLogic.cs
Normal file
@ -0,0 +1,106 @@
|
||||
using Microsoft.Extensions.Logging;
|
||||
using PolyclinicContracts.BindingModels;
|
||||
using PolyclinicContracts.BusinessLogicsContracts;
|
||||
using PolyclinicContracts.SearchModels;
|
||||
using PolyclinicContracts.StoragesContracts;
|
||||
using PolyclinicContracts.ViewModels;
|
||||
|
||||
namespace PolyclinicBusinessLogic.BusinessLogics
|
||||
{
|
||||
public class RecipeLogic : IRecipeLogic
|
||||
{
|
||||
|
||||
private readonly ILogger logger;
|
||||
private readonly IRecipeStorage recipeStorage;
|
||||
|
||||
public RecipeLogic(ILogger<RecipeLogic> logger, IRecipeStorage recipeStorage)
|
||||
{
|
||||
this.logger = logger;
|
||||
this.recipeStorage = recipeStorage;
|
||||
}
|
||||
public bool Create(RecipeBindingModel model)
|
||||
{
|
||||
CheckModel(model);
|
||||
if(recipeStorage.Insert(model) == null)
|
||||
{
|
||||
logger.LogWarning("Create operation failed");
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public bool Delete(RecipeBindingModel model)
|
||||
{
|
||||
CheckModel(model, false);
|
||||
if(recipeStorage.Delete(model) == null)
|
||||
{
|
||||
logger.LogWarning("Delete operation failed");
|
||||
return false;
|
||||
}
|
||||
logger.LogInformation("Delete Id:{Id}", model.Id);
|
||||
return true;
|
||||
}
|
||||
|
||||
public RecipeViewModel? ReadElement(RecipeSearchModel model)
|
||||
{
|
||||
if (model == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(model));
|
||||
}
|
||||
logger.LogInformation("ReadElement. Comment:{Comment}.Id:{ Id}", model.Comment, 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<RecipeViewModel>? ReadList(RecipeSearchModel? model)
|
||||
{
|
||||
logger.LogInformation("ReadList. Comment:{Comment}. Id:{ Id}", model?.Comment, 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 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(model.ProceduresCount <= 0)
|
||||
{
|
||||
throw new ArgumentNullException("Количество процедур не может быть равно нулю или быть меньше нуля", nameof(model));
|
||||
}
|
||||
if (string.IsNullOrEmpty(model.Comment))
|
||||
{
|
||||
throw new ArgumentNullException("Нет комментария", nameof(model.Comment));
|
||||
}
|
||||
logger.LogInformation("Recipe. Comment:{Comment}. Id: { Id}", model.Comment, model.Id);
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,109 @@
|
||||
using Microsoft.Extensions.Logging;
|
||||
using PolyclinicContracts.BindingModels;
|
||||
using PolyclinicContracts.BusinessLogicsContracts;
|
||||
using PolyclinicContracts.SearchModels;
|
||||
using PolyclinicContracts.StoragesContracts;
|
||||
using PolyclinicContracts.ViewModels;
|
||||
|
||||
namespace PolyclinicBusinessLogic.BusinessLogics
|
||||
{
|
||||
public class SymptomLogic : ISymptomLogic
|
||||
{
|
||||
private ILogger _logger;
|
||||
private ISymptomStorage _symptomStorage;
|
||||
|
||||
public SymptomLogic(ILogger logger, ISymptomStorage symptomStorage)
|
||||
{
|
||||
_logger = logger;
|
||||
_symptomStorage = symptomStorage;
|
||||
}
|
||||
|
||||
public bool Create(SymptomBindingModel model)
|
||||
{
|
||||
CheckModel(model);
|
||||
if (_symptomStorage.Insert(model) == null)
|
||||
{
|
||||
_logger.LogWarning("Insert operation failed");
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public bool Delete(SymptomBindingModel model)
|
||||
{
|
||||
CheckModel(model, false);
|
||||
_logger.LogInformation("Delete. Name:{Name}, Id:{Id}", model.Name, model.Id);
|
||||
if (_symptomStorage.Delete(model) == null)
|
||||
{
|
||||
_logger.LogWarning("Delete operation failed");
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public SymptomViewModel? ReadElement(SymptomSearchModel model)
|
||||
{
|
||||
if (model == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(model));
|
||||
}
|
||||
_logger.LogInformation("ReadElement. Name:{Name}, Id:{Id}", model.Name, model.Id);
|
||||
var element = _symptomStorage.GetElement(model);
|
||||
if (element == null)
|
||||
{
|
||||
_logger.LogWarning("ReadElement element not found");
|
||||
return null;
|
||||
}
|
||||
_logger.LogInformation("ReadElement find. Name:{Name}, Id:{Id}", element.Name, element.Id);
|
||||
return element;
|
||||
}
|
||||
|
||||
public List<SymptomViewModel>? ReadList(SymptomSearchModel? model)
|
||||
{
|
||||
_logger.LogInformation("ReadList. Name:{Name} Id:{Id}", model?.Name, model?.Id);
|
||||
var list = model == null ? _symptomStorage.GetFullList() : _symptomStorage.GetFilteredList(model);
|
||||
if (list == null)
|
||||
{
|
||||
_logger.LogWarning("ReadList return null list");
|
||||
return null;
|
||||
}
|
||||
_logger.LogInformation("ReadList. Count:{Count}", list.Count);
|
||||
return list;
|
||||
}
|
||||
|
||||
public bool Update(SymptomBindingModel model)
|
||||
{
|
||||
CheckModel(model);
|
||||
if (_symptomStorage.Update(model) == null)
|
||||
{
|
||||
_logger.LogWarning("Update operation failed");
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
private void CheckModel(SymptomBindingModel 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("Symptom. Name:{Name}. Id: {Id}", model.Name, model.Id);
|
||||
var element = _symptomStorage.GetElement(new SymptomSearchModel
|
||||
{
|
||||
Name = model.Name
|
||||
});
|
||||
if (element != null && element.Id != model.Id)
|
||||
{
|
||||
throw new InvalidOperationException("Симптом с таким названием уже есть");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
117
Polyclinic/PolyclinicBusinessLogic/BusinessLogics/UserLogic.cs
Normal file
117
Polyclinic/PolyclinicBusinessLogic/BusinessLogics/UserLogic.cs
Normal file
@ -0,0 +1,117 @@
|
||||
using Microsoft.Extensions.Logging;
|
||||
using PolyclinicContracts.BindingModels;
|
||||
using PolyclinicContracts.BusinessLogicsContracts;
|
||||
using PolyclinicContracts.SearchModels;
|
||||
using PolyclinicContracts.StoragesContracts;
|
||||
using PolyclinicContracts.ViewModels;
|
||||
|
||||
namespace PolyclinicBusinessLogic.BusinessLogics
|
||||
{
|
||||
public class UserLogic : IUserLogic
|
||||
{
|
||||
private ILogger _logger;
|
||||
private IUserStorage _userStorage;
|
||||
|
||||
public UserLogic(ILogger logger, IUserStorage userStorage)
|
||||
{
|
||||
_logger = logger;
|
||||
_userStorage = userStorage;
|
||||
}
|
||||
|
||||
public bool Create(UserBindingModel model)
|
||||
{
|
||||
CheckModel(model);
|
||||
if (_userStorage.Insert(model) == null)
|
||||
{
|
||||
_logger.LogWarning("Insert operation failed");
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public bool Delete(UserBindingModel model)
|
||||
{
|
||||
CheckModel(model, false);
|
||||
_logger.LogInformation("Delete. Id:{Id}", model.Id);
|
||||
if (_userStorage.Delete(model) == null)
|
||||
{
|
||||
_logger.LogWarning("Delete operation failed");
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public UserViewModel? ReadElement(UserSearchModel model)
|
||||
{
|
||||
if (model == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(model));
|
||||
}
|
||||
_logger.LogInformation("ReadElement. Email:{Email}. Id:{Id}", model.Email, model.Id);
|
||||
var element = _userStorage.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<UserViewModel>? ReadList(UserSearchModel? model)
|
||||
{
|
||||
_logger.LogInformation("ReadList. Email:{Email}. Id:{Id}", model?.Email, model?.Id);
|
||||
var list = model == null ? _userStorage.GetFullList() : _userStorage.GetFilteredList(model);
|
||||
if (list == null)
|
||||
{
|
||||
_logger.LogWarning("ReadList return null list");
|
||||
return null;
|
||||
}
|
||||
_logger.LogInformation("ReadList. Count:{Count}", list.Count);
|
||||
return list;
|
||||
}
|
||||
|
||||
public bool Update(UserBindingModel model)
|
||||
{
|
||||
CheckModel(model);
|
||||
if (_userStorage.Update(model) == null)
|
||||
{
|
||||
_logger.LogWarning("Update operation failed");
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
private void CheckModel(UserBindingModel model, bool withParams = true)
|
||||
{
|
||||
if (model == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(model));
|
||||
}
|
||||
if (!withParams)
|
||||
{
|
||||
return;
|
||||
}
|
||||
if (string.IsNullOrEmpty(model.Email))
|
||||
{
|
||||
throw new ArgumentNullException("Нет email пользователя", nameof(model.Email));
|
||||
}
|
||||
if (string.IsNullOrEmpty(model.Password))
|
||||
{
|
||||
throw new ArgumentNullException("Нет пароля пользователя", nameof(model.Password));
|
||||
}
|
||||
if (string.IsNullOrEmpty(model.FIO))
|
||||
{
|
||||
throw new ArgumentNullException("Нет фио пользователя", nameof(model.FIO));
|
||||
}
|
||||
_logger.LogInformation("User. Email:{Email}. Id: {Id}", model.Email, model.Id);
|
||||
var element = _userStorage.GetElement(new UserSearchModel
|
||||
{
|
||||
Email = model.Email
|
||||
});
|
||||
if (element != null && element.Id != model.Id)
|
||||
{
|
||||
throw new InvalidOperationException("Пользователь с таким email уже есть");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -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.Abstractions" Version="7.0.0" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\PolyclinicContracts\PolyclinicContracts.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
@ -3,6 +3,7 @@
|
||||
public class DiagnoseSearchModel
|
||||
{
|
||||
public int? Id { get; set; }
|
||||
public string? Name { get; set; }
|
||||
public int? UserId { get; set; }
|
||||
}
|
||||
}
|
||||
|
@ -3,5 +3,6 @@
|
||||
public class SymptomSearchModel
|
||||
{
|
||||
public int? Id { get; set; }
|
||||
public string?Name { get; set; }
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user