コード例 #1
0
        private string GetParents(int rightId)
        {
            var list = new List <int> {
                rightId
            };
            Sys_Right right = AllRights.Find(p => p.RightId == rightId);

            while (right.ParentId != 0)
            {
                int parentId = right.ParentId;
                list.Add(right.ParentId);
                right = AllRights.Find(p => p.RightId == parentId);
            }
            string result = string.Empty;

            for (int i = list.Count - 1; i >= 0; i--)
            {
                result += list[i] + "-";
            }
            if (result.EndsWith("-"))
            {
                result = result.Substring(0, result.LastIndexOf('-'));
            }
            return(result);
        }
コード例 #2
0
 private void DeleteRightChild(int rightId)
 {
     rightBL.Delete(rightId);
     AllRights.Remove(AllRights.Find(p => p.RightId == rightId));
     if (AllRights.FindAll(p => p.ParentId == rightId).Count > 0)
     {
         foreach (Sys_Right item in AllRights.FindAll(p => p.ParentId == rightId))
         {
             DeleteRightChild(item.RightId);
         }
     }
 }
コード例 #3
0
        public ActionResult RightEdit(int id = 0)
        {
            Sys_Right right = AllRights.Find(p => p.RightId == id) ?? new Sys_Right
            {
                RightId   = 0,
                Path      = "",
                RightDesc = "",
                RightName = ""
            };

            ViewData["allrights"] = AllRights;
            return(View(right));
        }
コード例 #4
0
        public JsonResult SaveRight(int rightID, string rightName, string rightDesc, int rightType, string rightPath,
                                    int parentRight, int?showOrder, string moduleName)
        {
            try
            {
                if (rightBL.Exists(rightName, rightID))
                {
                    return(Json(new
                    {
                        result = 0,
                        content = "权限名称重复!"
                    }, JsonRequestBehavior.AllowGet));
                }

                var right = AllRights.Find(p => p.RightId == rightID);

                if (right == null)
                {
                    //新增
                    right = new Sys_Right
                    {
                        RightName  = rightName,
                        RightDesc  = rightDesc,
                        RightType  = rightType,
                        Path       = rightPath,
                        ParentId   = parentRight,
                        ShowOrder  = showOrder,
                        ModuleName = moduleName
                    };
                    rightBL.Add(right);
                    lock (lockobj)
                    {
                        AllRights.Add(right);
                    }
                }
                else
                {
                    right.RightName  = rightName;
                    right.RightDesc  = rightDesc;
                    right.RightType  = rightType;
                    right.Path       = rightPath;
                    right.ShowOrder  = showOrder;
                    right.ModuleName = moduleName;

                    //修改前的判断
                    if (right.RightId == parentRight)
                    {
                        return(Json(new
                        {
                            result = 0,
                            content = "上级权限不能为本身!"
                        }, JsonRequestBehavior.AllowGet));
                    }
                    var childs = new List <int>();

                    GetChildRights(right.RightId, childs);

                    if (childs.IndexOf(parentRight) >= 0)
                    {
                        return(Json(new
                        {
                            result = 0,
                            content = "上级权限也不能为本身的子权限!"
                        }, JsonRequestBehavior.AllowGet));
                    }

                    right.ParentId = parentRight;
                    rightBL.Update(right);
                    lock (lockobj)
                    {
                        AllRights.Remove(AllRights.Find(p => p.RightId == rightID));
                        AllRights.Add(right);
                    }
                }
                return(Json(new
                {
                    result = 1,
                    content = "保存成功"
                }, JsonRequestBehavior.AllowGet));
            }
            catch
            {
                return(Json(new
                {
                    result = 0,
                    content = "保存失败"
                }, JsonRequestBehavior.AllowGet));
            }
        }