Merge branch 'stage6_partial_business_logic' of https://git.is.ulstu.ru/ns.potapov/PIbd-21_CourseWork_Polyclinic_BeSick into stage6_partial_business_logic

This commit is contained in:
Никита Потапов 2024-04-29 22:52:02 +04:00
commit 70e50610c5
2 changed files with 161 additions and 12 deletions

View File

@ -1,35 +1,113 @@
using PolyclinicContracts.BindingModels; using Microsoft.Extensions.Logging;
using PolyclinicContracts.BindingModels;
using PolyclinicContracts.BusinessLogicsContracts; using PolyclinicContracts.BusinessLogicsContracts;
using PolyclinicContracts.SearchModels; using PolyclinicContracts.SearchModels;
using PolyclinicContracts.StoragesContracts;
using PolyclinicContracts.ViewModels; using PolyclinicContracts.ViewModels;
namespace PolyclinicBusinessLogic.BusinessLogics namespace PolyclinicBusinessLogic.BusinessLogics
{ {
public class ProcedureLogic : IProcedureLogic 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) public bool Create(ProcedureBindingModel model)
{ {
throw new NotImplementedException(); CheckModel(model);
if (procedureStorage.Insert(model) == null)
{
logger.LogWarning("Insert operation failed");
return false;
}
return true;
} }
public bool Delete(ProcedureBindingModel model) public bool Delete(ProcedureBindingModel model)
{ {
throw new NotImplementedException(); 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) public ProcedureViewModel? ReadElement(ProcedureSearchModel model)
{ {
throw new NotImplementedException(); 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) public List<ProcedureViewModel>? ReadList(ProcedureSearchModel? model)
{ {
throw new NotImplementedException(); 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) public bool Update(ProcedureBindingModel model)
{ {
throw new NotImplementedException(); 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("Процедура с таким названием уже есть");
}
} }
} }
} }

View File

@ -1,35 +1,106 @@
using PolyclinicContracts.BindingModels; using Microsoft.Extensions.Logging;
using PolyclinicContracts.BindingModels;
using PolyclinicContracts.BusinessLogicsContracts; using PolyclinicContracts.BusinessLogicsContracts;
using PolyclinicContracts.SearchModels; using PolyclinicContracts.SearchModels;
using PolyclinicContracts.StoragesContracts;
using PolyclinicContracts.ViewModels; using PolyclinicContracts.ViewModels;
namespace PolyclinicBusinessLogic.BusinessLogics namespace PolyclinicBusinessLogic.BusinessLogics
{ {
public class RecipeLogic : IRecipeLogic 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) public bool Create(RecipeBindingModel model)
{ {
throw new NotImplementedException(); CheckModel(model);
if(recipeStorage.Insert(model) == null)
{
logger.LogWarning("Create operation failed");
return false;
}
return true;
} }
public bool Delete(RecipeBindingModel model) public bool Delete(RecipeBindingModel model)
{ {
throw new NotImplementedException(); 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) public RecipeViewModel? ReadElement(RecipeSearchModel model)
{ {
throw new NotImplementedException(); 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) public List<RecipeViewModel>? ReadList(RecipeSearchModel? model)
{ {
throw new NotImplementedException(); 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) public bool Update(RecipeBindingModel model)
{ {
throw new NotImplementedException(); 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);
} }
} }
} }