예제 #1
0
        /// <summary>
        /// 批量保存角色
        /// </summary>
        /// <param name="userInfo">用户</param>
        /// <param name="roleEntites">角色列表</param>
        /// <returns>影响行数</returns>
        public int BatchSave(BaseUserInfo userInfo, List <BaseRoleEntity> roleEntites)
        {
            int result = 0;

            var parameter = ServiceInfo.Create(userInfo, MethodBase.GetCurrentMethod());

            ServiceUtil.ProcessUserCenterWriteDbWithTransaction(userInfo, parameter, (dbHelper) =>
            {
                string tableName = userInfo.SystemCode + "Role";
                var manager      = new BaseRoleManager(dbHelper, userInfo, tableName);
                result           = manager.BatchSave(roleEntites);
                // clude:380405622 如果Enable=0,则BaseRoleUser中的用户角色对应关系 enable=0;如果Enable=1,则BaseRoleUser中的用户角色对应关系 enable=1
                tableName = BaseSystemInfo.SystemCode + "UserRole";
                List <KeyValuePair <string, object> > keyValuePairs = new List <KeyValuePair <string, object> >();
                foreach (BaseRoleEntity roleEntity in roleEntites)
                {
                    keyValuePairs.Clear();
                    keyValuePairs.Add(new KeyValuePair <string, object>(BaseUserRoleEntity.FieldRoleId, roleEntity.Id));
                    if (roleEntity.Enabled == 0)
                    {
                        new BaseUserRoleManager(dbHelper, userInfo, tableName).SetProperty(keyValuePairs, new KeyValuePair <string, object>(BaseUserRoleEntity.FieldEnabled, "0"));
                    }
                    else
                    {
                        new BaseUserRoleManager(dbHelper, userInfo, tableName).SetProperty(keyValuePairs, new KeyValuePair <string, object>(BaseUserRoleEntity.FieldEnabled, "1"));
                    }
                }
            });
            return(result);
        }
예제 #2
0
        /// <summary>
        /// 批量保存角色
        /// </summary>
        /// <param name="userInfo">用户</param>
        /// <param name="roleEntites">角色列表</param>
        /// <returns>影响行数</returns>
        public int BatchSave(BaseUserInfo userInfo, List <BaseRoleEntity> roleEntites)
        {
            // 写入调试信息
            #if (DEBUG)
            int milliStart = BaseBusinessLogic.StartDebug(userInfo, MethodBase.GetCurrentMethod());
            #endif

            // 加强安全验证防止未授权匿名调用
            #if (!DEBUG)
            LogOnService.UserIsLogOn(userInfo);
            #endif

            int returnValue = 0;
            using (IDbHelper dbHelper = DbHelperFactory.GetHelper(BaseSystemInfo.UserCenterDbType))
            {
                try
                {
                    dbHelper.Open(UserCenterDbConnection);
                    dbHelper.BeginTransaction();
                    string tableName = BaseRoleEntity.TableName;
                    if (!string.IsNullOrEmpty(BaseSystemInfo.SystemCode))
                    {
                        tableName = BaseSystemInfo.SystemCode + "Role";
                    }
                    BaseRoleManager roleManager = new BaseRoleManager(dbHelper, userInfo, tableName);
                    returnValue = roleManager.BatchSave(roleEntites);
                    BaseLogManager.Instance.Add(dbHelper, userInfo, serviceName, AppMessage.RoleService_BatchSave, MethodBase.GetCurrentMethod());
                    dbHelper.CommitTransaction();
                }
                catch (Exception ex)
                {
                    dbHelper.RollbackTransaction();
                    BaseExceptionManager.LogException(dbHelper, userInfo, ex);
                    throw ex;
                }
                finally
                {
                    dbHelper.Close();
                }
            }

            // 写入调试信息
            #if (DEBUG)
            BaseBusinessLogic.EndDebug(MethodBase.GetCurrentMethod(), milliStart);
            #endif

            return(returnValue);
        }