Реализовал логику болезней

This commit is contained in:
Никита Потапов 2024-04-29 23:00:36 +04:00
parent 6a8a2ae37c
commit b36674cb86
2 changed files with 81 additions and 6 deletions

View File

@ -1,35 +1,109 @@
using PolyclinicContracts.BindingModels;
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)
{
throw new NotImplementedException();
CheckModel(model);
if (_diagnoseStorage.Insert(model) == null)
{
_logger.LogWarning("Insert operation failed");
return false;
}
return true;
}
public bool Delete(DiagnoseBindingModel model)
{
throw new NotImplementedException();
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)
{
throw new NotImplementedException();
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)
{
throw new NotImplementedException();
_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)
{
throw new NotImplementedException();
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("Болезнь с таким названием уже есть");
}
}
}
}

View File

@ -3,6 +3,7 @@
public class DiagnoseSearchModel
{
public int? Id { get; set; }
public string? Name { get; set; }
public int? UserId { get; set; }
}
}