public IActionResult AddRole(string roleName) { try { var result = _roleRespository.AddRole(roleName); return(ToJson(result ? HttpResult.Success : HttpResult.Fail, message: result ? "添加成功" : "添加失败")); } catch (Exception exc) { return(new JsonResult(new { result = 0, message = exc.Message }, new Newtonsoft.Json.JsonSerializerSettings() { ContractResolver = new LowercaseContractResolver() })); } }
public async Task <JsonResult> AddRole([ModelBinder(typeof(JsonNetBinder)), FromForm] AddRoleVm role) { var result = new ResultJsonNoDataInfo(); var respositoryResult = await RoleRespository.AddRole(role, UserToken); if (string.IsNullOrEmpty(respositoryResult)) { result.Status = ResultConfig.Ok; result.Info = ResultConfig.SuccessfulMessage; } else { result.Status = ResultConfig.Fail; result.Info = string.IsNullOrEmpty(respositoryResult) ? ResultConfig.FailMessage : respositoryResult; } return(Json(result)); }