/// <summary>
        /// 添加顶层节点
        /// </summary>
        /// <param name="module"></param>
        public void CreateAsTop(string cid)
        {
            DynamicAuthCatalog dac = DynamicAuthCatalog.Find(cid);

            this.CatalogCode = dac.Code;

            this.Path      = null;
            this.PathLevel = 0;

            this.DoCreate();
        }
        public static IList <DynamicPermission> GrantDAuths(IList <DynamicAuth> dauths, IList <string> datas, IList <string> operations, string pcatalog, string tag, string granterID, string granterName)
        {
            IList <DynamicPermission> rtnps = new List <DynamicPermission>();

            IList authIDs = dauths.Select(tent => tent.DynamicAuthID).ToList();

            DynamicPermission[] dps = DynamicPermission.FindAll(Expression.Eq("CatalogCode", pcatalog), Expression.In("AuthID", authIDs), Expression.In("Data", datas.ToList()));

            // 获取权限分类
            IList dacatalogcode = dauths.Select(tent => tent.CatalogCode).Distinct().ToList();

            DynamicAuthCatalog[] dac = DynamicAuthCatalog.FindAll(Expression.In("Code", dacatalogcode));

            foreach (DynamicAuth dauth in dauths)
            {
                DynamicAuthCatalog tdac = dac.First(tent => tent.Code == dauth.CatalogCode);
                IList <string>     defaultOperations = null;

                if (tdac != null)
                {
                    defaultOperations = tdac.GetDefauleOperations().Select(tent => tent.Code).ToList();
                }

                foreach (string data in datas)
                {
                    IEnumerable <DynamicPermission> tdps = dps.Where <DynamicPermission>(tent => tent.AuthID == dauth.DynamicAuthID && tent.Data == data && tent.CatalogCode == pcatalog);

                    if (tdps.Count() > 0)
                    {
                        if (operations != null && operations.Count > 0)
                        {
                            foreach (DynamicPermission tdp in tdps)
                            {
                                if (operations != null && operations.Count() > 0)
                                {
                                    tdp.AddOperation(operations);
                                }
                                else if (defaultOperations != null)
                                {
                                    // 添加默认操作
                                    tdp.AddOperation(defaultOperations);
                                }

                                if (tag != null)
                                {
                                    tdp.Tag = tag;
                                }

                                tdp.Update();

                                rtnps.Add(tdp);
                            }
                        }
                    }
                    else
                    {
                        DynamicPermission dp = new DynamicPermission();

                        dp.AuthID          = dauth.DynamicAuthID;
                        dp.AuthCatalogCode = dauth.CatalogCode;
                        dp.Data            = data;
                        dp.CatalogCode     = pcatalog;
                        dp.CreaterID       = granterID;
                        dp.CreaterName     = granterName;
                        dp.Name            = string.Format("{0} to {1}", dauth.Name, data);

                        if (tag != null)
                        {
                            // 设置tag
                            dp.Tag = tag;
                        }

                        if (operations != null && operations.Count() > 0)
                        {
                            dp.AddOperation(operations);
                        }
                        else if (defaultOperations != null)
                        {
                            // 添加默认操作
                            dp.AddOperation(defaultOperations);
                        }

                        dp.Create();

                        rtnps.Add(dp);
                    }
                }
            }

            return(rtnps);
        }