From 11cb574c3acb59563f99057ebec7b1ab264cc394 Mon Sep 17 00:00:00 2001 From: kotcheshir73 Date: Mon, 12 Apr 2021 12:35:05 +0400 Subject: [PATCH] =?UTF-8?q?=D1=81=D0=B1=D1=80=D0=BE=D1=81=20=D0=BF=D0=B0?= =?UTF-8?q?=D1=80=D0=BE=D0=BB=D1=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Employee/ControlEmployeeElement.cs | 34 ++++++++++++++++++- .../Lecturer/ControlLecturerElement.cs | 34 ++++++++++++++++++- 2 files changed, 66 insertions(+), 2 deletions(-) diff --git a/DepartmentPortal/Department/DepartmentWindowsDesktop/EntityControls/Employee/ControlEmployeeElement.cs b/DepartmentPortal/Department/DepartmentWindowsDesktop/EntityControls/Employee/ControlEmployeeElement.cs index 8610312..9c73499 100644 --- a/DepartmentPortal/Department/DepartmentWindowsDesktop/EntityControls/Employee/ControlEmployeeElement.cs +++ b/DepartmentPortal/Department/DepartmentWindowsDesktop/EntityControls/Employee/ControlEmployeeElement.cs @@ -10,6 +10,7 @@ using ModuleTools.BusinessLogics; using ModuleTools.Extensions; using SecurityBusinessLogic.BindingModels; using SecurityBusinessLogic.BusinessLogics; +using SecurityBusinessLogic.ViewModels; using System; using System.Collections.Generic; @@ -36,7 +37,8 @@ namespace DepartmentWindowsDesktop.EntityControls { ControlOnMoveElem = new Dictionary { - { "ToolStripMenuItemAddUser", ("Добавить пользователя", (object sender, EventArgs e) => { AddUser(); }) } + { "ToolStripMenuItemAddUser", ("Добавить пользователя", (object sender, EventArgs e) => { AddUser(); }) }, + { "ToolStripMenuItemPasswordReset", ("Сброс пароля пользователя", (object sender, EventArgs e) => { PasswordReset(); }) } } }; @@ -85,5 +87,35 @@ namespace DepartmentWindowsDesktop.EntityControls } } } + + /// + /// Сброс пароля пользователя + /// + private void PasswordReset() + { + if (_element == null) + { + return; + } + var model = new EmployeeSetBindingModel(); + if (FillModel(model)) + { + var logic = DependencyManager.Instance.Resolve(); + var user = logic.GetElement(new UserGetBindingModel { Id = _element.UserId }); + if (user == null) + { + DialogHelper.MessageException(logic.Errors, "Ошибка при получении пользователя"); + return; + } + user.Password = model.DateBirth.ToShortDateString(); + user = logic.Update(Mapper.MapToClass(user, true)); + if (user == null) + { + DialogHelper.MessageException(logic.Errors, "Ошибка при получении пользователя"); + return; + } + DialogHelper.MessageInformation("Пароль сброшен", "Успех"); + } + } } } \ No newline at end of file diff --git a/DepartmentPortal/Department/DepartmentWindowsDesktop/EntityControls/Lecturer/ControlLecturerElement.cs b/DepartmentPortal/Department/DepartmentWindowsDesktop/EntityControls/Lecturer/ControlLecturerElement.cs index 16d6534..2a8e6b7 100644 --- a/DepartmentPortal/Department/DepartmentWindowsDesktop/EntityControls/Lecturer/ControlLecturerElement.cs +++ b/DepartmentPortal/Department/DepartmentWindowsDesktop/EntityControls/Lecturer/ControlLecturerElement.cs @@ -10,6 +10,7 @@ using ModuleTools.BusinessLogics; using ModuleTools.Extensions; using SecurityBusinessLogic.BindingModels; using SecurityBusinessLogic.BusinessLogics; +using SecurityBusinessLogic.ViewModels; using System; using System.Collections.Generic; @@ -33,7 +34,8 @@ namespace DepartmentWindowsDesktop.EntityControls { ControlOnMoveElem = new Dictionary { - { "ToolStripMenuItemAddUser", ("Добавить пользователя", (object sender, EventArgs e) => { AddUser(); }) } + { "ToolStripMenuItemAddUser", ("Добавить пользователя", (object sender, EventArgs e) => { AddUser(); }) }, + { "ToolStripMenuItemPasswordReset", ("Сброс пароля пользователя", (object sender, EventArgs e) => { PasswordReset(); }) } } }; @@ -82,5 +84,35 @@ namespace DepartmentWindowsDesktop.EntityControls } } } + + /// + /// Сброс пароля пользователя + /// + private void PasswordReset() + { + if (_element == null) + { + return; + } + var model = new LecturerSetBindingModel(); + if (FillModel(model)) + { + var logic = DependencyManager.Instance.Resolve(); + var user = logic.GetElement(new UserGetBindingModel { Id = _element.UserId }); + if (user == null) + { + DialogHelper.MessageException(logic.Errors, "Ошибка при получении пользователя"); + return; + } + user.Password = model.DateBirth.ToShortDateString(); + user = logic.Update(Mapper.MapToClass(user, true)); + if (user == null) + { + DialogHelper.MessageException(logic.Errors, "Ошибка при получении пользователя"); + return; + } + DialogHelper.MessageInformation("Пароль сброшен", "Успех"); + } + } } } \ No newline at end of file