using System;

using System.Web;

using System.Web.Configuration;

 

 

/// <summary>

/// Class used to read and store user preferences for the application

/// </summary>

public class AppCookie

{

 

    //

    // Constructors

    //

 

 

    /// <summary>

    /// Creates a new instance of a AppCookie object

    /// </summary>

    public AppCookie()

    {

 

        // Local Variables

 

        // Begin

 

        if (HttpContext.Current.Request.Cookies[WebConfigurationManager.AppSettings["AppCookieName"]] == null)

        {

 

            this.PreferencesCookie = new HttpCookie(WebConfigurationManager.AppSettings["AppCookieName"]);

            this.PreferredTheme = string.Empty;

 

        }// end if

        else

        {

 

            this.PreferencesCookie = HttpContext.Current.Request.Cookies[WebConfigurationManager.AppSettings["AppCookieName"]];

 

        }// end else

 

    }// end AppCookie

 

 

    //

    // Event Handlers

    //

 

 

    /* none */

 

 

    //

    // Methods

    //

 

 

    /// <summary>

    /// Saves the preference cookie to the users browser

    /// </summary>

    public void Save()

    {

 

        // Local Variables

 

        // Begin

 

        this.PreferencesCookie.Expires = DateTime.Now.AddDays(30.0);

        HttpContext.Current.Response.Cookies.Add(this.PreferencesCookie);

 

    }// end Save

 

 

    //

    // Properties

    //

 

 

    private HttpCookie _w;

    /// <summary>

    /// Gets or sets the preference cookie for the class

    /// </summary>

    private HttpCookie PreferencesCookie

    {

 

        get { return this._w; }

        set { this._w = value; }

 

    }// end PreferencesCookie

 

 

    /// <summary>

    /// Gets or sets the preferred theme for the user

    /// </summary>

    public string PreferredTheme

    {

 

        get { return this.PreferencesCookie["Theme"].ToString(); }

        set { this.PreferencesCookie["Theme"] = value; }

 

    }// end PreferredTheme

 

} // end class AppCookie