2021-04-04 10:18:45 +04:00
|
|
|
|
using DepartmentBusinessLogic.BindingModels;
|
|
|
|
|
using DepartmentBusinessLogic.BusinessLogics;
|
|
|
|
|
using DepartmentBusinessLogic.ViewModels;
|
2021-04-08 14:27:21 +04:00
|
|
|
|
using DesktopTools.BaseControls;
|
2021-04-04 10:18:45 +04:00
|
|
|
|
using DesktopTools.Controls;
|
2021-04-08 14:27:21 +04:00
|
|
|
|
using DesktopTools.Helpers;
|
2021-04-04 10:18:45 +04:00
|
|
|
|
using DesktopTools.Interfaces;
|
2021-04-08 10:37:47 +04:00
|
|
|
|
using DesktopTools.Models;
|
2021-04-08 14:27:21 +04:00
|
|
|
|
using ModuleTools.BusinessLogics;
|
|
|
|
|
using ModuleTools.Extensions;
|
|
|
|
|
using SecurityBusinessLogic.BindingModels;
|
|
|
|
|
using SecurityBusinessLogic.BusinessLogics;
|
2021-04-04 10:18:45 +04:00
|
|
|
|
using System;
|
2021-04-08 14:27:21 +04:00
|
|
|
|
using System.Collections.Generic;
|
2021-04-04 10:18:45 +04:00
|
|
|
|
|
|
|
|
|
namespace DepartmentWindowsDesktop.EntityControls
|
|
|
|
|
{
|
|
|
|
|
public partial class ControlLecturerElement :
|
|
|
|
|
GenericControlEntityElement<LecturerGetBindingModel, LecturerSetBindingModel, LecturerListViewModel, LecturerViewModel, LecturerBusinessLogic>,
|
|
|
|
|
IGenericControlEntityElement
|
|
|
|
|
{
|
|
|
|
|
public ControlLecturerElement()
|
|
|
|
|
{
|
|
|
|
|
InitializeComponent();
|
|
|
|
|
Title = "Преподаватель";
|
|
|
|
|
ControlId = new Guid("62a30c94-56eb-4df8-8cc2-9c1b937413e5");
|
|
|
|
|
_genericControlViewEntityElement = this;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public IControl GetInstanceGenericControl() => new ControlLecturerElement() { ControlId = Guid.NewGuid() };
|
2021-04-08 10:37:47 +04:00
|
|
|
|
|
2021-04-08 14:27:21 +04:00
|
|
|
|
public ControlViewEntityElementConfiguration GetConfigControl() => new()
|
|
|
|
|
{
|
|
|
|
|
ControlOnMoveElem = new Dictionary<string, (string Title, EventHandler Event)>
|
|
|
|
|
{
|
|
|
|
|
{ "ToolStripMenuItemAddUser", ("Добавить пользователя", (object sender, EventArgs e) => { AddUser(); }) }
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
private void AddUser()
|
|
|
|
|
{
|
|
|
|
|
var model = new LecturerSetBindingModel();
|
|
|
|
|
if (FillModel(model))
|
|
|
|
|
{
|
|
|
|
|
var logic = DependencyManager.Instance.Resolve<UserBusinessLogic>();
|
|
|
|
|
var userName = $"{model.LastName}{(model.FirstName.IsNotEmpty() ? $" {model.FirstName[0]}." : string.Empty)}{(model.Patronymic.IsNotEmpty() ? $"{model.Patronymic[0]}." : string.Empty)}";
|
|
|
|
|
var result = logic.GetList(new UserGetBindingModel { UserNameForSearch = userName });
|
|
|
|
|
if (result != null)
|
|
|
|
|
{
|
|
|
|
|
if (result.List.Count > 1)
|
|
|
|
|
{
|
|
|
|
|
DialogHelper.MessageException("Существует несколько пользователей с такой сигнатурой", "Ошибка");
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
if (result.List.Count == 1)
|
|
|
|
|
{
|
|
|
|
|
model.UserId = result.List[0].Id;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
var newuser = logic.Create(new UserSetBindingModel
|
|
|
|
|
{
|
|
|
|
|
Login = userName,
|
|
|
|
|
Password = model.DateBirth.ToShortDateString(),
|
|
|
|
|
Avatar = model.Photo
|
|
|
|
|
});
|
|
|
|
|
if (newuser == null)
|
|
|
|
|
{
|
|
|
|
|
DialogHelper.MessageException(logic.Errors, "Ошибка при создании пользователя");
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
model.UserId = newuser.Id;
|
|
|
|
|
}
|
|
|
|
|
var controls = tabPageMain.Controls.Find($"ControlUserId", true);
|
|
|
|
|
if (controls != null)
|
|
|
|
|
{
|
|
|
|
|
(controls[0] as AbstractBaseControl).SetValue(model);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2021-04-04 10:18:45 +04:00
|
|
|
|
}
|
|
|
|
|
}
|