//------------------------------------------------------------------------------
// <copyright company="Telligent Systems">
//     Copyright (c) Telligent Systems Corporation.  All rights reserved.
// </copyright> 
//------------------------------------------------------------------------------

using System;
using System.Web.UI.WebControls;
using CommunityServer.Components;

namespace CommunityServer.Controls
{
    public class UserInfo : PlaceHolder
    {
        private User _user;
        private bool isCloakedUser = false;

        public User User {
            get {
                if ( _user == null ) {
                    Object state = ViewState[ "UserID" ];
                    if ( state != null ) {
                        Int32 userID = (Int32)state;
                        _user = Users.GetUser( userID, false );
                    }
                    else
                    {
                        _user = Users.GetUser(CSContext.Current.UserID,false);
                    }
                }
                return _user;
            }
            set {
                _user = value;
                if ( _user != null ) {
                    ViewState[ "UserID" ] = _user.UserID;
                } else {
                    ViewState.Remove( "UserID" );
                }
            }

        }

        /// <summary>
        /// Added to specify if this user should be displayed as anonymous
        /// </summary>
        public bool IsCloakedUser { 
            get { return isCloakedUser; }
            set { isCloakedUser = value; }
        }
    }
}