Beispiel #1
0
        /// <summary>
        /// 继承权限
        /// </summary>
        /// <param name="documentInfoId">被继承权限的节点ID</param>
        public static void InheritAuthority(string documentInfoId)
        {
            var entities = FormulaHelper.GetEntities <OfficeAutoEntities>();
            var list     = entities.Set <S_F_DocumentInfo>().Where(i => i.ParentID == documentInfoId && i.IsInherit == 1).ToList();

            foreach (S_F_DocumentInfo documentInfo in list)
            {
                S_F_DocumentInfo info = documentInfo;
                //删除原有权限设置
                entities.Set <S_F_DocumentFileAuthority>().Delete(i => i.DocumentInfoID == info.ID);
                entities.SaveChanges();

                //设置继承的权限
                var listAuth = entities.Set <S_F_DocumentFileAuthority>().Where(i => i.DocumentInfoID == documentInfoId);
                foreach (S_F_DocumentFileAuthority authority in listAuth)
                {
                    var newItem = new S_F_DocumentFileAuthority
                    {
                        ID             = FormulaHelper.CreateGuid(),
                        DocumentInfoID = info.ID,
                        AuthType       = authority.AuthType,
                        RoleType       = authority.RoleType,
                        RoleCode       = authority.RoleCode,
                        IsParentAuth   = 1
                    };
                    entities.Set <S_F_DocumentFileAuthority>().Add(newItem);
                }
                entities.SaveChanges();

                //递归处理子节点
                InheritAuthority(info.ID);
            }
        }
Beispiel #2
0
        public override JsonResult Save()
        {
            var entity = UpdateEntity <S_F_DocumentInfo>();

            //判断同级不能重名
            if (entities.Set <S_F_DocumentInfo>().Any(a => a.ParentID == entity.ParentID && a.Name == entity.Name && a.ID != entity.ID))
            {
                throw new Formula.Exceptions.BusinessValidationException("同层节点下名称不能重复");
            }

            var funcType = GetQueryString("FuncType");

            if (funcType == "insert")
            {
                //新增时处理权限继承的情况
                if (entity.IsInherit == 1)
                {
                    var list = entities.Set <S_F_DocumentFileAuthority>().Where(i => i.DocumentInfoID == entity.ParentID);
                    foreach (S_F_DocumentFileAuthority authority in list)
                    {
                        var newItem = new S_F_DocumentFileAuthority();
                        newItem.ID             = FormulaHelper.CreateGuid();
                        newItem.DocumentInfoID = entity.ID;
                        newItem.AuthType       = authority.AuthType;
                        newItem.RoleType       = authority.RoleType;
                        newItem.RoleCode       = authority.RoleCode;
                        newItem.IsParentAuth   = 1;
                        entities.Set <S_F_DocumentFileAuthority>().Add(newItem);
                    }
                }
            }

            entities.SaveChanges();

            PropertyInfo pi = typeof(S_F_DocumentInfo).GetProperty("ID");

            if (pi != null)
            {
                return(Json(new { ID = pi.GetValue(entity, null) }));
            }
            return(Json(new { ID = "" }));
        }