DepartmentProject/DepartmentPortal/Security/SecurityBusinessLogic/BusinessLogics/BackupBusinessLogic.cs

68 lines
1.7 KiB
C#
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

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;
}
}
}