/// <summary>
        /// 添加授权
        /// </summary>
        /// <param name="objectType">权限分类-1角色2用户</param>
        /// <param name="objectId">对象Id</param>
        /// <param name="appModuleIds">功能Id</param>
        public void SaveAppAuthorize(int objectType, string objectId, string[] appModuleIds )
        {
            IRepository db = new RepositoryFactory().BaseRepository().BeginTrans();
            try
            {
                db.Delete<AuthorizeEntity>(t => t.F_ObjectId == objectId);

                #region  功能
                foreach (string item in appModuleIds)
                {
                    AuthorizeEntity authorizeEntity = new AuthorizeEntity();
                    authorizeEntity.Create();
                    authorizeEntity.F_ObjectType = objectType;
                    authorizeEntity.F_ObjectId = objectId;
                    authorizeEntity.F_ItemType = 5;
                    authorizeEntity.F_ItemId = item;
                    db.Insert(authorizeEntity);
                }
                #endregion

                db.Commit();
            }
            catch (Exception ex)
            {
                db.Rollback();
                if (ex is ExceptionEx)
                {
                    throw;
                }
                else
                {
                    throw ExceptionEx.ThrowServiceException(ex);
                }
            }
        }
Esempio n. 2
0
        /// <summary>
        /// 添加授权
        /// </summary>
        /// <param name="objectType">权限分类-1角色2用户</param>
        /// <param name="objectId">对象Id</param>
        /// <param name="moduleIds">功能Id</param>
        /// <param name="moduleButtonIds">按钮Id</param>
        /// <param name="moduleColumnIds">视图Id</param>
        /// <param name="moduleForms">表单Id</param>
        public void SaveAuthorize(int objectType, string objectId, string[] moduleIds, string[] moduleButtonIds, string[] moduleColumnIds, string[] moduleForms)
        {
            IRepository db = new RepositoryFactory().BaseRepository().BeginTrans();

            try
            {
                db.Delete <AuthorizeEntity>(t => t.F_ObjectId == objectId && t.F_ItemType != 5);

                #region 功能
                foreach (string item in moduleIds)
                {
                    AuthorizeEntity authorizeEntity = new AuthorizeEntity();
                    authorizeEntity.Create();
                    authorizeEntity.F_ObjectType = objectType;
                    authorizeEntity.F_ObjectId   = objectId;
                    authorizeEntity.F_ItemType   = 1;
                    authorizeEntity.F_ItemId     = item;
                    db.Insert(authorizeEntity);
                }
                #endregion

                #region  钮
                foreach (string item in moduleButtonIds)
                {
                    AuthorizeEntity authorizeEntity = new AuthorizeEntity();
                    authorizeEntity.Create();
                    authorizeEntity.F_ObjectType = objectType;
                    authorizeEntity.F_ObjectId   = objectId;
                    authorizeEntity.F_ItemType   = 2;
                    authorizeEntity.F_ItemId     = item;
                    db.Insert(authorizeEntity);
                }
                #endregion

                #region 视图
                foreach (string item in moduleColumnIds)
                {
                    AuthorizeEntity authorizeEntity = new AuthorizeEntity();
                    authorizeEntity.Create();
                    authorizeEntity.F_ObjectType = objectType;
                    authorizeEntity.F_ObjectId   = objectId;
                    authorizeEntity.F_ItemType   = 3;
                    authorizeEntity.F_ItemId     = item;
                    db.Insert(authorizeEntity);
                }
                #endregion

                #region 表单
                foreach (string item in moduleForms)
                {
                    AuthorizeEntity authorizeEntity = new AuthorizeEntity();
                    authorizeEntity.Create();
                    authorizeEntity.F_ObjectType = objectType;
                    authorizeEntity.F_ObjectId   = objectId;
                    authorizeEntity.F_ItemType   = 4;
                    authorizeEntity.F_ItemId     = item;
                    db.Insert(authorizeEntity);
                }
                #endregion

                db.Commit();
            }
            catch (Exception ex)
            {
                db.Rollback();
                if (ex is ExceptionEx)
                {
                    throw;
                }
                else
                {
                    throw ExceptionEx.ThrowServiceException(ex);
                }
            }
        }