public ActionResult EditRole(RoleIM role) { if (ModelState.IsValid) { if (role.Id > 0) { Role vRole = _roleServices.GetById(role.Id); if (!vRole.IsSys) { vRole.RoleName = role.RoleName; vRole.Description = role.Description; _roleServices.Update(vRole); } else { // return new HttpStatusCodeResult(500, "系统角色不可编辑"); AR.SetWarning("系统角色不可编辑"); return(Json(AR)); } } else { var vm = _mapper.Map <Role>(role); _roleServices.Create(vm); } AR.SetSuccess(String.Format(Messages.AlertCreateSuccess, EntityNames.Role)); return(Json(AR)); } //return new HttpStatusCodeResult(500, "编辑角色失败"); AR.Setfailure("编辑角色失败"); return(Json(AR)); }
public ActionResult <RoleModel> Create([FromBody] RoleModel model) { try { if (ModelState.IsValid) { RoleModel record = _role.Create(model); return(Created("Test uri", record)); } else { return(ValidationProblem()); } } catch (Exception ex) { return(StatusCode(500, ex.Message)); } }
public ActionResult EditRole([Bind(Include = "Id,RoleName,Description")] Role role) { if (ModelState.IsValid) { if (role.Id > 0) { Role vRole = _roleServices.GetById(role.Id); if (!vRole.IsSys) { vRole.RoleName = role.RoleName; vRole.Description = role.Description; _roleServices.Update(vRole); } else { // return new HttpStatusCodeResult(500, "系统角色不可编辑"); AR.SetWarning("系统角色不可编辑"); return(Json(AR, JsonRequestBehavior.DenyGet)); } } else { _roleServices.Create(role); } var roles = _roleServices.GetAll().Where(r => r.Id != SettingsManager.Role.Founder); AR.Data = RenderPartialViewToString("_List", roles); AR.SetSuccess(String.Format(Messages.AlertCreateSuccess, EntityNames.Menu)); return(Json(AR, JsonRequestBehavior.DenyGet)); } else { //return new HttpStatusCodeResult(500, "编辑角色失败"); AR.Setfailure("编辑角色失败"); return(Json(AR, JsonRequestBehavior.DenyGet)); } }