2022-03-18 22:38:52 +04:00
|
|
|
|
using ToolsModule.BindingModels;
|
|
|
|
|
using ToolsModule.Enums;
|
|
|
|
|
using ToolsModule.Interfaces;
|
|
|
|
|
using ToolsModule.Models;
|
2021-04-02 20:46:41 +04:00
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
|
2022-03-18 22:38:52 +04:00
|
|
|
|
namespace ToolsModule.BusinessLogics
|
2021-04-02 20:46:41 +04:00
|
|
|
|
{
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Основа всех бизнес-логик
|
|
|
|
|
/// </summary>
|
|
|
|
|
public class CoreBusinessLogic
|
|
|
|
|
{
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Менеджер безопасности
|
|
|
|
|
/// </summary>
|
|
|
|
|
protected readonly ISecurityManager _security;
|
|
|
|
|
|
2021-04-05 10:08:49 +04:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Тип операции, скоторым работает логика
|
|
|
|
|
/// </summary>
|
|
|
|
|
protected AccessOperation _serviceOperation;
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Название сущности
|
|
|
|
|
/// </summary>
|
|
|
|
|
protected string _entity;
|
|
|
|
|
|
2021-04-02 20:46:41 +04:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Перечень ошибок при выполнении операции
|
|
|
|
|
/// </summary>
|
|
|
|
|
public List<(string Title, string Message)> Errors { get; protected set; }
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Основа всех бизнес-логик
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="service"></param>
|
|
|
|
|
public CoreBusinessLogic()
|
|
|
|
|
{
|
|
|
|
|
_security = DependencyManager.Instance.Resolve<ISecurityManager>();
|
|
|
|
|
Errors = new();
|
|
|
|
|
}
|
2021-04-05 10:08:49 +04:00
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Проверка доступности операции для пользователя
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="model"></param>
|
|
|
|
|
/// <param name="type"></param>
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
protected bool NoAccess(AccessBindingModel model, AccessType type)
|
|
|
|
|
{
|
|
|
|
|
if (_security.CheckAccess(new SecurityManagerCheckAccessModel(model, _serviceOperation, type, _entity)))
|
|
|
|
|
{
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
Errors.Add(("Ошибка безопасности", _security.ErrorMessage));
|
|
|
|
|
return true;
|
|
|
|
|
}
|
2021-04-02 20:46:41 +04:00
|
|
|
|
}
|
|
|
|
|
}
|