public JsonResult Create(PermissionScopeType obj) { try { NSession.SaveOrUpdate(obj); NSession.Flush(); } catch (Exception ee) { return Json(new { IsSuccess = false, ErrorMsg = "出错了" }); } return Json(new { IsSuccess = true }); }
public ActionResult SetMP(string a, string m, string p, int uid) { string[] ms = m.Split(new string[] { "," }, StringSplitOptions.RemoveEmptyEntries); string[] ps = p.Split(new string[] { "," }, StringSplitOptions.RemoveEmptyEntries); string[] fos = a.Split(new string[] { "," }, StringSplitOptions.RemoveEmptyEntries); PermissionScopeType sc = null; NSession.CreateQuery("delete from PermissionScopeType where ResourceCategory='" + ResourceCategoryEnum.User.ToString() + "' and ResourceId=" + uid).ExecuteUpdate(); foreach (var item in ms) { if (string.IsNullOrEmpty(item)) continue; sc = new PermissionScopeType(); sc.ResourceCategory = ResourceCategoryEnum.User.ToString(); sc.ResourceId = uid; sc.TargetCategory = TargetCategoryEnum.Module.ToString(); sc.TargetId = Convert.ToInt32(item); NSession.Save(sc); NSession.Flush(); } foreach (var item in ps) { if (string.IsNullOrEmpty(item)) continue; ; sc = new PermissionScopeType(); sc.ResourceCategory = ResourceCategoryEnum.User.ToString(); sc.ResourceId = uid; sc.TargetCategory = TargetCategoryEnum.PermissionItem.ToString(); sc.TargetId = Convert.ToInt32(item); NSession.Save(sc); NSession.Flush(); } foreach (var item in fos) { if (string.IsNullOrEmpty(item)) continue; ; sc = new PermissionScopeType(); sc.ResourceCategory = ResourceCategoryEnum.User.ToString(); sc.ResourceId = uid; sc.TargetCategory = TargetCategoryEnum.Account.ToString(); sc.TargetId = Convert.ToInt32(item); NSession.Save(sc); NSession.Flush(); } return Json(new { IsSuccess = true }); }