예제 #1
0
        /// <summary>
        /// 添加角色
        /// </summary>
        /// <param name="userInfo">用户</param>
        /// <param name="role">角色</param>
        /// <returns>主键</returns>
        public string AddRole(BaseUserInfo userInfo, string role)
        {
            // 加强安全验证防止未授权匿名调用
            #if (!DEBUG)
            LogOnService.UserIsLogOn(userInfo);
            #endif

            string returnValue = string.Empty;
            using (IDbHelper dbHelper = DbHelperFactory.GetHelper(BaseSystemInfo.UserCenterDbType))
            {
                try
                {
                    dbHelper.Open(UserCenterDbConnection);
                    BaseRoleManager roleManager = new BaseRoleManager(dbHelper, userInfo);
                    string          statusCode  = string.Empty;
                    BaseRoleEntity  roleEntity  = new BaseRoleEntity();
                    roleEntity.RealName = role;
                    roleEntity.Enabled  = 1;
                    returnValue         = roleManager.Add(roleEntity, out statusCode);
                }
                catch (Exception ex)
                {
                    BaseExceptionManager.LogException(dbHelper, userInfo, ex);
                    throw ex;
                }
                finally
                {
                    dbHelper.Close();
                }
            }

            return(returnValue);
        }
        /// <summary>
        /// 添加角色(同时添加用户,一个数据库事务里进行处理)
        /// </summary>
        /// <param name="userInfo">用户</param>
        /// <param name="entity">实体</param>
        /// <param name="userIds">用户主键数组</param>
        /// <param name="status">状态</param>
        /// <param name="statusMessage">返回状态信息</param>
        /// <returns>主键</returns>
        public string AddWithUser(BaseUserInfo userInfo, BaseRoleEntity entity, string[] userIds, out Status status, out string statusMessage)
        {
            var result = string.Empty;

            var returnCode    = Status.Ok;
            var returnMessage = string.Empty;

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

            ServiceUtil.ProcessUserCenterWriteDbWithTransaction(userInfo, parameter, (dbHelper) =>
            {
                // 这里是判断已经登录的用户是否有调用当前函数的权限,加强服务层被远程调用的安全性的
                var tableName = userInfo.SystemCode + "Role";
                var manager   = new BaseRoleManager(dbHelper, userInfo, tableName);
                result        = manager.Add(entity, out returnCode);
                if (!string.IsNullOrEmpty(result) && userIds != null && userIds.Length > 0)
                {
                    tableName       = userInfo.SystemCode + "UserRole";
                    var userManager = new BaseUserManager(dbHelper, userInfo, tableName);
                    // 小心异常,检查一下参数的有效性
                    if (userIds != null)
                    {
                        userManager.AddToRole(userInfo.SystemCode, userIds, new string[] { result });
                    }
                }
                returnMessage = manager.GetStateMessage(returnCode);
            });
            status        = returnCode;
            statusMessage = returnMessage;

            return(result);
        }
예제 #3
0
        /// <summary>
        /// 批量删除角色
        /// </summary>
        /// <param name="userInfo">用户</param>
        /// <param name="ids">主键数组</param>
        /// <returns>影响行数</returns>
        public int BatchDelete(BaseUserInfo userInfo, string[] ids)
        {
            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 = roleManager.BatchDelete(ids);

                BaseRoleEntity roleEntity = null;
                // 把删除的记录放到被删除的表里(表名后面加了后缀Deleted,也可以放在另外一个数据库里也可以的)
                var roleDeletedManager = new BaseRoleManager(dbHelper, userInfo, tableName + "Deleted");
                foreach (var id in ids)
                {
                    // 逐个删除,逐个备份
                    roleEntity = manager.GetObject(id);
                    // 先添加到被删除的表里,这时候原先数据的主键需要保留的,否则恢复数据时可能会乱套
                    roleDeletedManager.Add(roleEntity);
                    // 数据备份好后再进行删除处理
                    result += manager.Delete(id);
                }
            });

            return(result);
        }
예제 #4
0
        /// <summary>
        /// 添加角色
        /// </summary>
        /// <param name="userInfo">用户</param>
        /// <param name="entity">实体</param>
        /// <param name="statusCode">返回状态码</param>
        /// <param name="statusMessage">返回状态信息</param>
        /// <returns>主键</returns>
        public string Add(BaseUserInfo userInfo, BaseRoleEntity entity, out string statusCode, out string statusMessage)
        {
            string result = string.Empty;

            string returnCode    = string.Empty;
            string returnMessage = string.Empty;

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

            ServiceUtil.ProcessUserCenterWriteDbWithTransaction(userInfo, parameter, (dbHelper) =>
            {
                // 这里是判断已经登录的用户是否有调用当前函数的权限,加强服务层被远程调用的安全性的,会损失服务器的性能
                // var permissionManager = new BasePermissionManager(result);
                // if (permissionManager.CheckPermissionByUser(result.Id, "RoleAdmin.Add", "添加角色"))
                // {
                string tableName = userInfo.SystemCode + "Role";
                var manager      = new BaseRoleManager(dbHelper, userInfo, tableName);
                result           = manager.Add(entity, out returnCode);
                returnMessage    = manager.GetStateMessage(returnCode);
                // }
                //else
                //{
                //    StatusCode = Status.AccessDeny.ToString();
                //    permissionManager.GetStateMessage(StatusCode);
                //}
            });
            statusCode    = returnCode;
            statusMessage = returnMessage;

            return(result);
        }
예제 #5
0
        /// <summary>
        /// 添加角色
        /// </summary>
        /// <param name="userInfo">用户</param>
        /// <param name="roleEntity">实体</param>
        /// <param name="statusCode">返回状态码</param>
        /// <param name="statusMessage">返回状态信息</param>
        /// <returns>主键</returns>
        public string Add(BaseUserInfo userInfo, BaseRoleEntity roleEntity, out string statusCode, out string statusMessage)
        {
            // 写入调试信息
            #if (DEBUG)
            int milliStart = BaseBusinessLogic.StartDebug(userInfo, MethodBase.GetCurrentMethod());
            #endif

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

            string returnValue = string.Empty;
            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.Add(roleEntity, out statusCode);
                    statusMessage = roleManager.GetStateMessage(statusCode);
                    BaseLogManager.Instance.Add(dbHelper, userInfo, serviceName, AppMessage.RoleService_Add, 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);
        }
예제 #6
0
        /// <summary>
        /// 添加角色
        /// </summary>
        /// <param name="userInfo">用户</param>
        /// <param name="role">角色</param>
        /// <returns>主键</returns>
        public string AddRole(BaseUserInfo userInfo, string role)
        {
            string result = string.Empty;

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

            ServiceUtil.ProcessUserCenterWriteDb(userInfo, parameter, (dbHelper) =>
            {
                var roleManager           = new BaseRoleManager(dbHelper, userInfo);
                string statusCode         = string.Empty;
                BaseRoleEntity roleEntity = new BaseRoleEntity();
                roleEntity.RealName       = role;
                roleEntity.Enabled        = 1;
                result = roleManager.Add(roleEntity, out statusCode);
            });
            return(result);
        }