Синхронизация студентов

This commit is contained in:
kotcheshir73 2022-03-18 10:22:34 +04:00
parent d79be9a8dc
commit 48ad010501
3 changed files with 532 additions and 499 deletions

View File

@ -9,6 +9,7 @@ using DesktopTools.Models;
using ModuleTools.Enums; using ModuleTools.Enums;
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Threading.Tasks;
namespace DepartmentWindowsDesktop.EntityControls namespace DepartmentWindowsDesktop.EntityControls
{ {
@ -43,7 +44,7 @@ namespace DepartmentWindowsDesktop.EntityControls
}, },
ControlOnMoveElem = new() ControlOnMoveElem = new()
{ {
{ "ToolStripMenuItemSyncOrders", ("Синхронизировать студентов", (object sender, EventArgs e) => { SyncOrders(); }) } { "ToolStripMenuItemSyncOrders", ("Синхронизировать студентов", async (object sender, EventArgs e) => { await SyncOrders (); }) }
} }
}; };
@ -51,9 +52,9 @@ namespace DepartmentWindowsDesktop.EntityControls
/// Синхронизация приказов /// Синхронизация приказов
/// </summary> /// </summary>
/// <returns></returns> /// <returns></returns>
private void SyncOrders() private async Task SyncOrders()
{ {
var flag = _businessLogic.SyncOrders(); var flag = await _businessLogic.SyncOrders();
if (!flag) if (!flag)
{ {
DialogHelper.MessageException(_businessLogic.Errors, "Ошибки при синхронизации"); DialogHelper.MessageException(_businessLogic.Errors, "Ошибки при синхронизации");

View File

@ -3,6 +3,8 @@ using ModuleTools.Enums;
using SecurityBusinessLogic.BindingModels; using SecurityBusinessLogic.BindingModels;
using SecurityBusinessLogic.Interfaces; using SecurityBusinessLogic.Interfaces;
using SecurityBusinessLogic.ViewModels; using SecurityBusinessLogic.ViewModels;
using System;
using System.Linq;
namespace SecurityBusinessLogic.BusinessLogics namespace SecurityBusinessLogic.BusinessLogics
{ {
@ -12,5 +14,47 @@ namespace SecurityBusinessLogic.BusinessLogics
public class UserBusinessLogic : GenericBusinessLogic<UserGetBindingModel, UserSetBindingModel, UserListViewModel, UserViewModel> public class UserBusinessLogic : GenericBusinessLogic<UserGetBindingModel, UserSetBindingModel, UserListViewModel, UserViewModel>
{ {
public UserBusinessLogic(IUserService service) : base(service, "Пользователи", AccessOperation.Пользователи) { } public UserBusinessLogic(IUserService service) : base(service, "Пользователи", AccessOperation.Пользователи) { }
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;
}
} }
} }