using System;
using System.Configuration;
using System.Linq;
using System.Web;

namespace WebApplication1.Models {
	public static class ModeleCompteurs {
		static public int NbDeVisiteurs;
		static public readonly string CheminFichierNbDeVisiteurs = ConfigurationManager.AppSettings["CheminFichierNbDeVisiteurs"];
		static public int NbDeVisitesDuNavigateurSurLaPage {
			get {
				object o = HttpContext.Current.Session["NbDeVisitesDuNavigateurSurLaPage"];
				return o == null ? 0 : (int)o;
			}
			set {
				HttpContext.Current.Session["NbDeVisitesDuNavigateurSurLaPage"] = value;
			}
		}
		static public int NbDeVisitesDeLUtilisateurSurLeSite {
			get {
				var response = HttpContext.Current.Response;
				if( response.Cookies.AllKeys.Contains( "NbDeVisitesDeLUtilisateurSurLeSite" ) ) {
					return int.Parse( response.Cookies["NbDeVisitesDeLUtilisateurSurLeSite"].Value );
				}
				else {
					var request = HttpContext.Current.Request;
					var cookie = request.Cookies["NbDeVisitesDeLUtilisateurSurLeSite"];
					if( cookie == null )
						return 0;
					else
						return int.Parse( cookie.Value );
				}
			}
			set {
				HttpContext.Current.Response.Cookies.Add( new HttpCookie( "NbDeVisitesDeLUtilisateurSurLeSite", value.ToString() ) { Expires = DateTime.Now.AddDays( 3 ) } );
			}
		}
	}
}
