61 lines
1.7 KiB
C#
61 lines
1.7 KiB
C#
using ToolsModule.BindingModels;
|
|
using ToolsModule.Enums;
|
|
using ToolsModule.Interfaces;
|
|
using ToolsModule.Models;
|
|
using System.Collections.Generic;
|
|
using ToolsModule.DependencyManagment;
|
|
|
|
namespace ToolsModule.BusinessLogics
|
|
{
|
|
/// <summary>
|
|
/// Основа всех бизнес-логик
|
|
/// </summary>
|
|
public class CoreBusinessLogic
|
|
{
|
|
/// <summary>
|
|
/// Менеджер безопасности
|
|
/// </summary>
|
|
protected readonly ISecurityManager _security;
|
|
|
|
/// <summary>
|
|
/// Тип операции, скоторым работает логика
|
|
/// </summary>
|
|
protected AccessOperation _serviceOperation;
|
|
|
|
/// <summary>
|
|
/// Название сущности
|
|
/// </summary>
|
|
protected string _entity;
|
|
|
|
/// <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();
|
|
}
|
|
|
|
/// <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;
|
|
}
|
|
}
|
|
} |