//更新角色 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 ? "更新成功" : "更新失败")); }
//添加角色 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 ? "创建成功" : "创建失败" })); }
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> /// <param name="message"></param> /// <returns></returns> public static bool AddOrUpdateRoleValidate(UpdateAndAddSystemRoleDto input, ref string message) { var success = false; if (input == null) { message = "数据不能够为空"; } else if (string.IsNullOrWhiteSpace(input.ID)) { message = "角色ID不能够为空"; } else if (input.ID.Length >= 64) { message = "角色ID不能超过64位"; } else if (!RegexHelper.OnlyContainCharacterAndDigitAndLine.IsMatch(input.ID)) { message = "角色ID只能包含英文,数字,以及-字符"; } else if (string.IsNullOrWhiteSpace(input.Name)) { message = "角色名称不能够为空"; } else if (input.Name.Length > 8) { message = "角色名称不能超过8个字符"; } else if (input.ClientIds == null) { message = "角色必须包含最少一个客户端"; } else { success = true; } return(success); }