68 lines
1.7 KiB
C#
68 lines
1.7 KiB
C#
using ModuleTools.BusinessLogics;
|
||
using ModuleTools.Enums;
|
||
using ModuleTools.Interfaces;
|
||
using ModuleTools.Models;
|
||
using SecurityBusinessLogic.BindingModels;
|
||
using SecurityBusinessLogic.Interfaces;
|
||
using System;
|
||
using System.Collections.Generic;
|
||
using System.Linq;
|
||
using System.Text;
|
||
using System.Threading.Tasks;
|
||
|
||
namespace SecurityBusinessLogic.BusinessLogics
|
||
{
|
||
/// <summary>
|
||
/// Логика работы с бекапом
|
||
/// </summary>
|
||
public class BackupBusinessLogic
|
||
{
|
||
private IBackupService _service;
|
||
|
||
/// <summary>
|
||
/// Менеджер безопасности
|
||
/// </summary>
|
||
private ISecurityManager _security;
|
||
|
||
/// <summary>
|
||
/// Перечень ошибок при выполнении операции
|
||
/// </summary>
|
||
public List<(string Title, string Message)> Errors { get; protected set; }
|
||
|
||
public BackupBusinessLogic(IBackupService service)
|
||
{
|
||
_service = service;
|
||
_security = DependencyManager.Instance.Resolve<ISecurityManager>();
|
||
Errors = new();
|
||
}
|
||
|
||
public bool CreateBackUp(BackupBindingModel model)
|
||
{
|
||
if (NoAccess())
|
||
{
|
||
return false;
|
||
}
|
||
var result = _service.CreateBackUp(model);
|
||
if (!result.IsSucceeded)
|
||
{
|
||
Errors.AddRange(result.Errors);
|
||
return false;
|
||
}
|
||
return true;
|
||
}
|
||
|
||
/// <summary>
|
||
/// Проверка доступности операции для пользователя
|
||
/// </summary>
|
||
/// <returns></returns>
|
||
private bool NoAccess()
|
||
{
|
||
if (_security.CheckAccess(new SecurityManagerCheckAccessModel(null, AccessOperation.РаботасБекапом, AccessType.View, "бекап")))
|
||
{
|
||
return false;
|
||
}
|
||
Errors.Add(("Ошибка безопасности", _security.ErrorMessage));
|
||
return true;
|
||
}
|
||
}
|
||
} |