Exemplo n.º 1
0
        /// <summary>
        /// 扮演用户
        /// </summary>
        /// <param name="id">用户主键</param>
        /// <param name="status">状态</param>
        /// <returns>用户类</returns>
        public BaseUserInfo Impersonation(int id, out Status status)
        {
            BaseUserInfo userInfo = null;
            // 获得登录信息
            var entity = new BaseUserLogonManager(DbHelper, UserInfo).GetEntityByUserId(id.ToString());

            // 只允许登录一次,需要检查是否自己重新登录了,或者自己扮演自己了
            if (!UserInfo.Id.Equals(id))
            {
                if (BaseSystemInfo.CheckOnline)
                {
                    if (entity.UserOnline > 0)
                    {
                        status = Status.ErrorOnline;
                        return(userInfo);
                    }
                }
            }

            var userEntity = GetEntity(id);

            userInfo = ConvertToUserInfo(userEntity);
            if (userEntity.IsStaff.Equals("1"))
            {
                // 获得员工的信息
                var staffEntity    = new BaseStaffEntity();
                var staffManager   = new BaseStaffManager(DbHelper, UserInfo);
                var dataTableStaff = staffManager.GetDataTableById(id.ToString());
                staffEntity.GetSingle(dataTableStaff);
                userInfo = staffManager.ConvertToUserInfo(userInfo, staffEntity);
            }
            status = Status.Ok;
            // 登录、重新登录、扮演时的在线状态进行更新
            var userLogonManager = new BaseUserLogonManager(DbHelper, UserInfo);

            userLogonManager.ChangeOnline(id);
            return(userInfo);
        }