2024-04-29 22:34:54 +04:00
|
|
|
|
using Microsoft.Extensions.Logging;
|
|
|
|
|
using PolyclinicContracts.BindingModels;
|
2024-04-29 22:01:58 +04:00
|
|
|
|
using PolyclinicContracts.BusinessLogicsContracts;
|
|
|
|
|
using PolyclinicContracts.SearchModels;
|
2024-04-29 22:34:54 +04:00
|
|
|
|
using PolyclinicContracts.StoragesContracts;
|
2024-04-29 22:01:58 +04:00
|
|
|
|
using PolyclinicContracts.ViewModels;
|
|
|
|
|
|
|
|
|
|
namespace PolyclinicBusinessLogic.BusinessLogics
|
|
|
|
|
{
|
|
|
|
|
public class SymptomLogic : ISymptomLogic
|
|
|
|
|
{
|
2024-04-29 22:34:54 +04:00
|
|
|
|
private ILogger _logger;
|
|
|
|
|
private ISymptomStorage _symptomStorage;
|
|
|
|
|
|
2024-05-23 14:58:59 +04:00
|
|
|
|
public SymptomLogic(ILogger<SymptomLogic> logger, ISymptomStorage symptomStorage)
|
2024-04-29 22:34:54 +04:00
|
|
|
|
{
|
|
|
|
|
_logger = logger;
|
|
|
|
|
_symptomStorage = symptomStorage;
|
|
|
|
|
}
|
|
|
|
|
|
2024-04-29 22:01:58 +04:00
|
|
|
|
public bool Create(SymptomBindingModel model)
|
|
|
|
|
{
|
2024-04-29 22:34:54 +04:00
|
|
|
|
CheckModel(model);
|
|
|
|
|
if (_symptomStorage.Insert(model) == null)
|
|
|
|
|
{
|
|
|
|
|
_logger.LogWarning("Insert operation failed");
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
return true;
|
2024-04-29 22:01:58 +04:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public bool Delete(SymptomBindingModel model)
|
|
|
|
|
{
|
2024-04-29 22:34:54 +04:00
|
|
|
|
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;
|
2024-04-29 22:01:58 +04:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public SymptomViewModel? ReadElement(SymptomSearchModel model)
|
|
|
|
|
{
|
2024-04-29 22:34:54 +04:00
|
|
|
|
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;
|
2024-04-29 22:01:58 +04:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public List<SymptomViewModel>? ReadList(SymptomSearchModel? model)
|
|
|
|
|
{
|
2024-04-29 22:34:54 +04:00
|
|
|
|
_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;
|
2024-04-29 22:01:58 +04:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public bool Update(SymptomBindingModel model)
|
|
|
|
|
{
|
2024-04-29 22:34:54 +04:00
|
|
|
|
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))
|
|
|
|
|
{
|
2024-04-29 23:00:24 +04:00
|
|
|
|
throw new ArgumentNullException("Нет названия симптома", nameof(model.Name));
|
2024-04-29 22:34:54 +04:00
|
|
|
|
}
|
|
|
|
|
_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)
|
|
|
|
|
{
|
2024-04-29 23:00:24 +04:00
|
|
|
|
throw new InvalidOperationException("Симптом с таким названием уже есть");
|
2024-04-29 22:34:54 +04:00
|
|
|
|
}
|
2024-04-29 22:01:58 +04:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|