/// <summary> /// 通过代码查找角色 /// </summary> /// <param name="id">角色ID</param> /// <returns>系统角色Model</returns> public async Task <SystemRoleDto> FindRoleByIdAsync(string id) { using (var db = _contextFactory()) { try { var entity = await db.SystemRoles.FirstOrDefaultAsync(p => p.ID == id); if (entity == null) { return(null); } var role = new SystemRoleDto() { ID = entity.ID, ClientIds = entity.ClientIds, Name = entity.Name }; return(role); } catch (Exception ex) { Log.Error(ex, "SystemRole FindRoleByIdAsync Error"); return(null); } } }
private void ExecuteSelectedJobFunctionChangedCommand(SystemRoleDto systemRoleDto) { var jobFunctionRole = EditingDto.SystemRoles.JobFunctionRole; if (jobFunctionRole == null && systemRoleDto != null) { var requestDispatcher = _asyncRequestDispatcherFactory.CreateAsyncRequestDispatcher(); requestDispatcher.Add(new ReviseStaffJobFunctionRoleRequest(EditingDto.Key, systemRoleDto.Key)); requestDispatcher.ProcessRequests(HandleReviseJobFunctionCompleted, HandleSaveJobFunctionException); IsStaffAccountAccessLoading = true; } if (jobFunctionRole != null && systemRoleDto != EditingDto.SystemRoles.JobFunctionRole.SystemRole) { var requestDispatcher = _asyncRequestDispatcherFactory.CreateAsyncRequestDispatcher(); if (systemRoleDto != null) { requestDispatcher.Add(new ReviseStaffJobFunctionRoleRequest(EditingDto.Key, systemRoleDto.Key)); requestDispatcher.ProcessRequests(HandleReviseJobFunctionCompleted, HandleSaveJobFunctionException); } else { requestDispatcher.Add(new RemoveStaffJobFunctionRoleRequest(EditingDto.Key)); requestDispatcher.ProcessRequests(HandleRemoveJobFunctionCompleted, HandleSaveJobFunctionException); } IsStaffAccountAccessLoading = true; } }
private void ProcessSystemRoleResponses(SystemRoleDto systemRoleDto, List <DataErrorInfo> validationErrors, bool isInitializing = false) { IsLoading = false; if (validationErrors.Count() == 0) { SystemRoleDto = systemRoleDto; if (isInitializing) { InitializeTaskAndTaskGroupList(); } else { RefreshSystemRoleLists(); } } else { var errors = new StringBuilder(); errors.AppendLine("The following errors occurred:"); foreach (var validationError in validationErrors) { errors.AppendLine(validationError.Message); } _userDialogService.ShowDialog(errors.ToString(), "Errors", UserDialogServiceOptions.Ok); //Wrapper.EditableDto.AddDataErrorInfo(validationError); } }
public async Task CreateRoleAsync_Correct() { var service = new SystemRoleAppService(this.CreateDbContext); var id1 = Guid.NewGuid().ToString("N"); var id2 = Guid.NewGuid().ToString("N"); var role1 = new SystemRoleDto() { ClientIds = "1,2,4", ID = id1, Name = "Test" }; var role2 = new SystemRoleDto() { ClientIds = "11132132132111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111", ID = id2, Name = "fdassssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssss", }; await service.CreateRoleAsync(role1); await service.CreateRoleAsync(role2); using (var db = this.CreateDbContext()) { var temp1 = await db.SystemRoles.FirstOrDefaultAsync(u => u.ID == id1); var temp2 = await db.SystemRoles.FirstOrDefaultAsync(u => u.ID == id2); Assert.IsNotNull(temp1); db.SystemRoles.Remove(temp2); db.SystemRoles.Remove(temp1); await db.SaveChangesAsync(); } }
//更新角色 public async Task <IActionResult> OnPostUpdateRoleAsync([FromBody] UpdateAndAddSystemRoleDto input) { var success = false; if (string.IsNullOrEmpty(input?.ID) || input.ClientIds.Count == 0) { return(new JsonResult(new { success = success, message = "角色代码或者客户端不能为空" })); } var dto = new SystemRoleDto() { ID = input.ID, Name = input.Name, }; var clientManager = this._remoteServiceClient.CreateClientAppService(); foreach (string split in input.ClientIds) { var client = await clientManager.FindClientByIdAsync(split); if (client == null) { continue; } dto.ClientIds += client.ClientId + ","; } dto.ClientIds = dto.ClientIds.Remove(dto.ClientIds.Length - 1, 1); success = await this._systemRoleService.UpdateRoleAsync(dto); return(new JsonResult(new { success = success, message = success ? "更新成功" : "更新失败" })); }
public async Task <IActionResult> UpdateRoleAsync([FromBody] UpdateAndAddSystemRoleDto input) { string message = string.Empty; bool success = DataModelValidate.AddOrUpdateRoleValidate(input, ref message); if (!success) { return(Json(success, null, message)); } var dto = new SystemRoleDto() { ID = input.ID, Name = input.Name, }; var clientManager = this._remoteServiceClient.CreateClientAppService(); foreach (string split in input.ClientIds) { var client = await clientManager.FindClientByIdAsync(split); if (client == null) { continue; } dto.ClientIds += client.ClientId + ","; } dto.ClientIds = dto.ClientIds.Remove(dto.ClientIds.Length - 1, 1); success = await this._systemRoleService.UpdateRoleAsync(dto); return(Json(success, null, success ? "更新成功" : "更新失败")); }
private void ExecuteEditJobFunctionCommand(SystemRoleDto systemRoleDto) { _popupService.ShowPopup( "EditJobFunctionView", "Edit", "Job Function", new[] { new KeyValuePair <string, string> ("SystemRoleKey", systemRoleDto.Key.ToString()) }, false, PopupClosed); }
private void ExecuteDeleteJobFunction(SystemRoleDto systemRoleDto) { var result = _userDialogService.ShowDialog( "Are you sure you want to delete?", "Confirmation", UserDialogServiceOptions.OkCancel); if (result == UserDialogServiceResult.Ok) { DeleteJobFunction(systemRoleDto.Key); } }
public ActionResult SaveRole(SystemRoleDto model) { if (model.Id == null) { Ioc.Resolve <ISystemMemberService>().AddRole(model); } else { Ioc.Resolve <ISystemMemberService>().UpdateRole(model); } return(Success()); }
/// <summary> /// Handles the request. /// </summary> /// <param name="request">The request.</param> /// <param name="response">The response.</param> protected override void HandleRequest(CreateSystemRoleRequest request, SystemRoleCommandResponse response) { var systemRole = _systemRoleFactory.CreateSystemRole(request.Name, request.Description, request.SystemRoleType); if (Success) { FlushSession(); var systemRoleDto = new SystemRoleDto(); response.SystemRole = Mapper.Map(systemRole, systemRoleDto); } }
private void ExecuteRevokeSystemRoleCommand(SystemRoleDto obj) { var requestDispatcher = _asyncRequestDispatcherFactory.CreateAsyncRequestDispatcher(); requestDispatcher.Add( new RevokeSystemRoleRequest { SystemRoleKey = SystemRoleDto.Key, SystemRoleKeysToBeRevoked = new List <long> { obj.Key } }); IsLoading = true; requestDispatcher.ProcessRequests(HandleRevokeSystemRoleCompleted, HandleRevokeSystemRoleException); }
private void ExecuteEditTaskOrTaskGroupCommand(SystemRoleDto systemRoleDto) { _popupService.ShowPopup( "EditTaskAndTaskGroupView", "Edit", "Task/Task Group", new[] { new KeyValuePair <string, string> ("SystemRoleKey", systemRoleDto.Key.ToString()), new KeyValuePair <string, string> ("SystemRoleType", systemRoleDto.SystemRoleType.ToString()) }, false, PopupClosed); }
/// <summary> /// Handles the request. /// </summary> /// <param name="request">The request.</param> /// <param name="response">The response.</param> protected override void HandleRequest(CloneSystemRoleRequest request, SystemRoleCommandResponse response) { var session = SessionProvider.GetSession(); var systemRoleKey = request.SystemRoleKey; var systemRole = session.Get <SystemRole> (systemRoleKey); var clonedSystemRole = systemRole.Clone(); if (Success) { FlushSession(); var systemRoleDto = new SystemRoleDto(); response.SystemRole = Mapper.Map(clonedSystemRole, systemRoleDto); } }
//添加角色 public async Task <IActionResult> OnPostCreateRoleAsync([FromBody] UpdateAndAddSystemRoleDto input) { var success = false; if (string.IsNullOrEmpty(input?.ID) || input.ClientIds.Count == 0) { return(new JsonResult(new { success = success, message = "角色代码或者客户端不能为空" })); } var dto = new SystemRoleDto() { ID = input.ID, Name = input.Name, ClientIds = string.Join(",", input.ClientIds) }; success = await this._systemRoleService.CreateRoleAsync(dto); return(new JsonResult(new { success = success, message = success ? "创建成功" : "创建失败" })); }
/// <summary> /// 创建系统角色 /// </summary> /// <param name="srDto">系统角色Model</param> /// <returns></returns> public async Task <bool> CreateRoleAsync(SystemRoleDto srDto) { using (var db = _contextFactory()) { try { var role = new SystemRole() { ID = srDto.ID, ClientIds = srDto.ClientIds, Name = srDto.Name }; db.SystemRoles.Add(role); return(await db.SaveChangesAsync() > 0); } catch (Exception ex) { Log.Error(ex, "SystemRole CreateRoleAsync Error"); return(false); } } }
public async Task <IActionResult> AddRoleAsync([FromBody] UpdateAndAddSystemRoleDto input) { var success = false; string message = string.Empty; success = DataModelValidate.AddOrUpdateRoleValidate(input, ref message); if (!success) { return(Json(success, null, message)); } var dto = new SystemRoleDto() { ID = input.ID, Name = input.Name, ClientIds = string.Join(",", input.ClientIds) }; success = await this._systemRoleService.CreateRoleAsync(dto); return(Json(success, null, success ? "创建成功" : "创建失败")); }
/// <summary> /// 查看一个角色下面的所有用户 /// </summary> /// <param name="input"></param> /// <returns></returns> public async Task <IActionResult> OnPostRoleUsers([FromBody] SystemRoleDto input) { if (input == null || string.IsNullOrEmpty(input.ID)) { return(new JsonResult(new { success = false, message = "参数错误" })); } var rawRoleUsers = await this._userRoleService.FindUsersByRoleIdAsync(input.ID); var list = new List <object>(); foreach (UserIdsDto rawRoleUser in rawRoleUsers) { var itemId = new ItemId(new Guid(rawRoleUser.UserID)); //获取到那个manager var userManager = this._remoteServiceClient.CreateUserAppService(itemId); var user = await userManager.FindByIdAsync(itemId); if (user == null) { continue; } //var roles = (await this._userRoleService.FindRolesByUserIdAsync(user.Id.ToString())) // .Select(u => // { // if (string.IsNullOrEmpty(u.Name)) // return u.ID; // return u.Name; // }).ToList(); //list.Add(new { id = user.Id.ToString(), username = user.Username, name = user.Name, mail = user.Email, roles = roles, state = user.IsActive }); var _state = "禁用"; if (user.IsActive.HasValue && user.IsActive.Value) { _state = "可用"; } list.Add(new { id = user.Id.ToString(), username = user.Username, name = user.Name, mail = user.Email, state = _state }); } return(new JsonResult(new { success = true, datas = list })); }
/// <summary> /// 更新系统角色 /// </summary> /// <param name="srDto">系统角色Model</param> /// <returns></returns> public async Task <bool> UpdateRoleAsync(SystemRoleDto srDto) { using (var db = _contextFactory()) { try { var entity = await db.SystemRoles.FirstOrDefaultAsync(p => p.ID == srDto.ID); if (entity == null) { return(false); } entity.Name = srDto.Name; entity.ClientIds = srDto.ClientIds; db.SystemRoles.Update(entity); return(await db.SaveChangesAsync() > 0); } catch (Exception ex) { Log.Error(ex, "SystemRole UpdateRoleAsync Error"); return(false); } } }
public async Task <IActionResult> DeleteRole([FromBody] SystemRoleDto input) { var success = await this._systemRoleService.DeleteRoleAsync(input.ID); return(Json(success, null, success ? "删除成功" : "删除失败")); }
//删除角色 public async Task <IActionResult> OnPostDeleteRole([FromBody] SystemRoleDto input) { var success = await this._systemRoleService.DeleteRoleAsync(input.ID); return(new JsonResult(new { success = success, message = success ? "删除成功" : "删除失败" })); }
private void NavigateToCreateCommand(KeyValuePair <string, string>[] parameters) { SystemRoleDto = new SystemRoleDto(); InitializeTaskAndTaskGroupList(); }