/// <summary>
		/// Signs in a user and creates a remember token cookie on the user browser. 
		/// The instance variable CurrentUser is set to the signed in User.
		/// </summary>
		public static void SignIn(User signInUser)
		{
			HttpCookie rememberToken = new HttpCookie("RememberToken");
			rememberToken.Value = signInUser.RememberMe();
			rememberToken.Expires = DateTime.Now.AddMinutes(15);
			
			HttpContext.Current.Response.Cookies.Add(rememberToken);
		}
		/// <summary>
		/// Updates the user RememberToken in the database with a new given value
		/// </summary>
		public static void UpdateUserRememberToken(User user, string RememberToken)
		{
			// Find user in database
			// update RememberToken
			using (ISession session = DatabaseManager.OpenSession()) 
			{
                ITransaction transaction = session.BeginTransaction();
				
                IQuery query = session.CreateQuery("from User where UserId = :id");
				query.SetParameter("id", user.UserId); //ToString()?
				
                User userToUpdate = query.List<User>()[0];
                userToUpdate.RememberToken = RememberToken;
                transaction.Commit();

            }
		}
		/// <summary>
		/// Adds a new user to the database.
		/// </summary>
		public static void AddUserToDatabase(User user)
		{
			using (ISession session = DatabaseManager.OpenSession())
			{
				ITransaction transaction = session.BeginTransaction();
				
				user.CreatedAt = DateTime.Now;
				user.UpdatedAt = DateTime.Now;
				user.EncryptPassword();
				
				session.Save(user);
				
				try
				{
					transaction.Commit();
					session.Close();
				}
				
				catch
				{
					session.Close();
					// if exception is duplicate in database throw the below exception.
					throw new Exception("Sorry. That user is already taken.");
				}
			}
		}