public JsonResult GetRoleByID(string roleId) { return(ExecuteFunctionRun(() => { OrgJobViewModel model = new OrgJobViewModel(); OThinker.Organization.OrgPost post = this.Engine.Organization.GetUnit(roleId) as OThinker.Organization.OrgPost; if (post == null) { return Json(model, JsonRequestBehavior.AllowGet); } //上级角色 OThinker.Organization.OrgPost parentPost = this.Engine.Organization.GetUnit(post.SuperiorID) as OThinker.Organization.OrgPost; model = new OrgJobViewModel { ObjectID = post.ObjectID, Code = post.Code, DisplayName = post.Name, Description = post.Description, ParentPostObjectID = parentPost == null ? "" : parentPost.ObjectID, ParentPostName = parentPost == null ? "" : parentPost.Name, Sortkey = post.SortKey, RoleLevel = post.JobLevel }; return Json(model, JsonRequestBehavior.AllowGet); })); }
/// <summary> /// 保存或更新角色 /// </summary> /// <param name="model"></param> /// <returns></returns> public JsonResult SaveRole(OrgJobViewModel model) { return(ExecuteFunctionRun(() => { ActionResult result = new ActionResult(false, ""); try { if (string.IsNullOrEmpty(model.ObjectID)) { //编码必须以字母开始,不让创建到数据库表字段时报错 System.Text.RegularExpressions.Regex regex = new System.Text.RegularExpressions.Regex("^[a-zA-Z\\u4e00-\\u9fa5][0-9a-zA-Z\\u4e00-\\u9fa5_]*$"); if (!regex.Match(model.Code).Success) { result.Success = false; result.Message = "EditBizObjectSchemaProperty.Msg4"; return Json(result); } List <OThinker.Organization.Unit> listunits = this.Engine.Organization.GetAllUnits(OThinker.Organization.UnitType.Post); var filterPost = listunits.Where(s => ((OThinker.Organization.OrgPost)s).Code == model.Code).FirstOrDefault(); if (filterPost != null) { result.Success = false; result.Message = "msgGlobalString.CodeDuplicate"; return Json(result, JsonRequestBehavior.DenyGet); } //新增 OThinker.Organization.OrgPost post = new OThinker.Organization.OrgPost() { Code = model.Code, Name = model.DisplayName, SuperiorID = model.ParentPostObjectID, Description = model.Description, SortKey = model.Sortkey, JobLevel = model.RoleLevel }; this.Engine.Organization.AddUnit(this.UserValidator.UserID, post); } else { //更新 OThinker.Organization.OrgPost post = this.Engine.Organization.GetUnit(model.ObjectID) as OThinker.Organization.OrgPost; if (post != null) { post.Name = model.DisplayName; post.SuperiorID = model.ParentPostObjectID; post.Description = model.Description; post.JobLevel = model.RoleLevel; post.SortKey = model.Sortkey; } this.Engine.Organization.UpdateUnit(this.UserValidator.UserID, post); } } catch (Exception ex) { result.Message = "msgGlobalString.SaveFailed"; result.Extend = ex.Message; return Json(result, JsonRequestBehavior.DenyGet); } result.Success = true; result.Message = "msgGlobalString.SaveSucced"; return Json(result, JsonRequestBehavior.DenyGet); })); }