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