2021-03-28 19:15:55 +04:00
|
|
|
|
using ModuleTools.BusinessLogics;
|
|
|
|
|
using ModuleTools.Enums;
|
2021-03-26 20:09:52 +04:00
|
|
|
|
using SecurityBusinessLogic.BindingModels;
|
|
|
|
|
using SecurityBusinessLogic.Interfaces;
|
|
|
|
|
using SecurityBusinessLogic.ViewModels;
|
2022-03-18 10:22:34 +04:00
|
|
|
|
using System;
|
|
|
|
|
using System.Linq;
|
2021-03-26 20:09:52 +04:00
|
|
|
|
|
|
|
|
|
namespace SecurityBusinessLogic.BusinessLogics
|
|
|
|
|
{
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Логика работы с пользователями
|
|
|
|
|
/// </summary>
|
2021-03-29 12:13:47 +04:00
|
|
|
|
public class UserBusinessLogic : GenericBusinessLogic<UserGetBindingModel, UserSetBindingModel, UserListViewModel, UserViewModel>
|
2021-03-26 20:09:52 +04:00
|
|
|
|
{
|
|
|
|
|
public UserBusinessLogic(IUserService service) : base(service, "Пользователи", AccessOperation.Пользователи) { }
|
2022-03-18 10:22:34 +04:00
|
|
|
|
|
|
|
|
|
public UserViewModel GetOrCreateUser(UserGetBindingModel model, string password)
|
|
|
|
|
{
|
|
|
|
|
Errors.Clear();
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
model.HaveRight = !NoAccess(model, AccessType.View);
|
|
|
|
|
if (model.HaveRight && !_allowSimpleView)
|
|
|
|
|
{
|
|
|
|
|
throw new MethodAccessException("Нет прав на получение списка");
|
|
|
|
|
}
|
|
|
|
|
var result = Service.Read(model);
|
|
|
|
|
if (result.IsSucceeded)
|
|
|
|
|
{
|
|
|
|
|
return result.Result as UserViewModel;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (result.Errors.First().Message == "Элемент удален")
|
|
|
|
|
{
|
|
|
|
|
result = Service.Restore(model);
|
|
|
|
|
}
|
|
|
|
|
else if (result.Errors.First().Message == "Элемент не найден")
|
|
|
|
|
{
|
|
|
|
|
result = Service.Create(new UserSetBindingModel
|
|
|
|
|
{
|
|
|
|
|
Login = model.Login,
|
|
|
|
|
Password = password
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
if (!result.IsSucceeded)
|
|
|
|
|
{
|
|
|
|
|
Errors.AddRange(result.Errors);
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
return result.Result as UserViewModel;
|
|
|
|
|
}
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
|
|
|
|
Errors.Add(("Ошибка получения", ex.Message));
|
|
|
|
|
}
|
|
|
|
|
return null;
|
|
|
|
|
}
|
2021-03-26 20:09:52 +04:00
|
|
|
|
}
|
|
|
|
|
}
|