Example #1
0
    protected void saveFoodOrDrinkItem_Click(object sender, EventArgs e)
    {
        string passwordResetSessionValue = "";
        string usernameValue = "";

        try
        {
            HttpCookie passwordResetSessionCookie = new HttpCookie("passwordResetSession");
            passwordResetSessionCookie = Request.Cookies["passwordResetSession"];
            passwordResetSessionValue = passwordResetSessionCookie.Value.ToString();
        }
        catch (Exception)
        {
            passwordResetSessionValue = "cookie exception";
        }

        if (passwordResetSessionValue != "" && passwordResetSessionValue != "cookie exception")
        {
            Response.Cookies["passwordResetSession"].Expires = DateTime.Now.AddMinutes(-2);
        }

        try
        {
            HttpCookie myCookie = new HttpCookie("userSession");
            myCookie = Request.Cookies["userSession"];
            usernameValue = myCookie.Value.ToString();
        }
        catch (Exception)
        {
            usernameValue = "cookie exception";
        }

        if (usernameValue != "" && usernameValue != "cookie exception")
        {
            Controllers.RequestPersonalInformation importRequestPersonalInformation = new Controllers.RequestPersonalInformation();
            Controllers.RequestCalorieCounter importRequestCalorieCounter = new Controllers.RequestCalorieCounter();

            string foodOrBeverageItem = this.foodOrBeverageItem.Text;
            string numberOfCaloriesPerServing = this.numberOfCaloriesPerServing.Text;
            string numberOfServings = this.numberOfServings.Text;

            this.webPageBodyLoggedIn.Visible = true;
            this.webPageBodyNotLoggedIn.Visible = false;
            this.welcomeMessage.Text = importRequestPersonalInformation.requestWelcomeMessage(usernameValue);
            this.addFoodItemMessage.Text = importRequestCalorieCounter.requestAddFoodItem(foodOrBeverageItem, numberOfCaloriesPerServing, numberOfServings, usernameValue);
            this.calorieCounterSummary.Text = importRequestCalorieCounter.requestCalorieCounterSummary(usernameValue);

            if (importRequestPersonalInformation.requestWelcomeMessage(usernameValue) == "<label>Hi, username not found!</label>\n")
            {
                Response.Cookies["userSession"].Expires = DateTime.Now.AddDays(-14);

                Response.Redirect("http://www.timothysdigitalsolutions.somee.com/");
            }
        }
    }