87 lines
2.8 KiB
C#
87 lines
2.8 KiB
C#
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 ProcedureLogic : IProcedureLogic
|
|
{
|
|
private readonly ILogger _logger;
|
|
private readonly IProcedureStorage _procedureStorage;
|
|
|
|
public ProcedureLogic(ILogger<ProcedureLogic> logger, IProcedureStorage procedureStorage)
|
|
{
|
|
_logger = logger;
|
|
_procedureStorage = procedureStorage;
|
|
}
|
|
public ProcedureViewModel? ReadElement(ProcedureSearchModel model)
|
|
{
|
|
if (model == null)
|
|
{
|
|
throw new ArgumentNullException(nameof(model));
|
|
}
|
|
_logger.LogInformation("ReadElement. Id:{ Id}", 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. Id:{ Id}", 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);
|
|
}
|
|
}
|
|
}
|