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

67 lines
1.7 KiB
C#
Raw Normal View History

using ModuleTools.BusinessLogics;
using ModuleTools.Enums;
using ModuleTools.Models;
using SecurityBusinessLogic.Interfaces;
using System;
namespace SecurityBusinessLogic.BusinessLogics
{
/// <summary>
/// Логика синхронизации пользователей
/// </summary>
public class SynchronizationBusinessLogic : CoreBusinessLogic
{
/// <summary>
/// Серивс для работы с бекапом
/// </summary>
private readonly ISynchronizationService _service;
/// <summary>
/// Логика работы с бекапом
/// </summary>
/// <param name="service"></param>
public SynchronizationBusinessLogic(ISynchronizationService service) => _service = service;
/// <summary>
/// Запуск синхронизации
/// </summary>
/// <param name="model"></param>
/// <returns></returns>
public bool RunSynchronization()
{
try
{
if (NoAccess())
{
return false;
}
var result = _service.RunSynchronization();
if (!result.IsSucceeded)
{
Errors.AddRange(result.Errors);
return false;
}
return true;
}
catch (Exception ex)
{
Errors.Add(("Ошибка", ex.Message));
return false;
}
}
/// <summary>
/// Проверка доступности операции для пользователя
/// </summary>
/// <returns></returns>
private bool NoAccess()
{
if (_security.CheckAccess(new SecurityManagerCheckAccessModel(null, AccessOperation.Синхронизация, AccessType.Delete, "Синхронизация")))
{
return false;
}
Errors.Add(("Ошибка безопасности", _security.ErrorMessage));
return true;
}
}
}