예제 #1
0
파일: SysMenuBLL.cs 프로젝트: sowill/renshi
        /// <summary>
        /// 创建一个模块
        /// </summary>
        /// <param name="validationErrors">返回的错误信息</param>
        /// <param name="db">数据库上下文</param>
        /// <param name="entity">一个模块</param>
        /// <returns></returns>
        public bool Create(ref ValidationErrors validationErrors, SysEntities db, SysMenu entity)
        {
            int count = 1;

            foreach (string item in entity.SysRoleId.GetIdSort())
            {
                SysRole sys = new SysRole {
                    Id = item
                };
                db.SysRole.Attach(sys);
                entity.SysRole.Add(sys);
                count++;
            }

            repository.Create(db, entity);
            if (count == repository.Save(db))
            {
                return(true);
            }
            else
            {
                validationErrors.Add("创建出错了");
            }
            return(false);
        }
예제 #2
0
        /// <summary>
        /// 创建一个菜单
        /// </summary>
        /// <param name="validationErrors">返回的错误信息</param>
        /// <param name="db">数据库上下文</param>
        /// <param name="entity">一个菜单</param>
        /// <returns></returns>
        public bool Create(ref ValidationErrors validationErrors, SysEntities db, SysMenu entity)
        {
            int count = 1;

            foreach (string item in entity.SysOperationId.GetIdSort())
            {
                SysOperation sys = new SysOperation {
                    Id = item
                };
                db.SysOperation.Attach(sys);
                entity.SysOperation.Add(sys);
                count++;
            }

            repository.Create(db, entity);
            if (count == repository.Save(db))
            {
                //创建后重置菜单编码
                List <int> flags = new List <int>();//层级
                GetMenus2(null, flags);
                db.SaveChanges();
                return(true);
            }
            else
            {
                validationErrors.Add("创建出错了");
            }
            return(false);
        }