protected void Page_Load(object sender, EventArgs e) { string passwordResetSessionValue = ""; string usernameValue = ""; string randomBackgroundImageValue = ""; 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"; } try { HttpCookie randomBackgroundImageCookie = new HttpCookie("randomBackgroundImage"); randomBackgroundImageCookie = Request.Cookies["randomBackgroundImage"]; randomBackgroundImageValue = randomBackgroundImageCookie.Value.ToString(); } catch (Exception) { randomBackgroundImageValue = "cookie exception"; } if (randomBackgroundImageValue == "" || randomBackgroundImageValue == "cookie exception") { Controllers.RequestCalorieCounter importRequestCalorieCounter = new Controllers.RequestCalorieCounter(); Response.Cookies["randomBackgroundImage"].Value = importRequestCalorieCounter.createSiteBackgroundCookie(); Response.Cookies["randomBackgroundImage"].Expires = DateTime.Now.AddDays(1); this.siteBackground.Text = importRequestCalorieCounter.requestSiteBackground(randomBackgroundImageValue); } else { Controllers.RequestCalorieCounter importRequestCalorieCounter = new Controllers.RequestCalorieCounter(); this.siteBackground.Text = importRequestCalorieCounter.requestSiteBackground(randomBackgroundImageValue); } if (usernameValue != "" && usernameValue != "cookie exception") { Controllers.RequestPersonalInformation importRequestPersonalInformation = new Controllers.RequestPersonalInformation(); Controllers.RequestCalorieCounter importRequestCalorieCounter = new Controllers.RequestCalorieCounter(); string action = Request.QueryString["action"]; if (action == "add food item") { this.addFoodItemSection.Visible = true; this.addExerciseActivitySection.Visible = false; this.instructionsSection.Visible = false; this.calorieCounterForm.Action = HttpContext.Current.Request.Url.AbsoluteUri; } else if (action == "add exercise activity") { this.addFoodItemSection.Visible = false; this.addExerciseActivitySection.Visible = true; this.instructionsSection.Visible = false; this.calorieCounterForm.Action = HttpContext.Current.Request.Url.AbsoluteUri; } else { this.addFoodItemSection.Visible = false; this.addExerciseActivitySection.Visible = false; this.instructionsSection.Visible = true; this.calorieCounterForm.Action = "http://www.timothysdigitalsolutions.somee.com/calorie-counter/"; } this.webPageBodyLoggedIn.Visible = true; this.webPageBodyNotLoggedIn.Visible = false; this.welcomeMessage.Text = importRequestPersonalInformation.requestWelcomeMessage(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/"); } } else { this.webPageBodyLoggedIn.Visible = false; this.webPageBodyNotLoggedIn.Visible = true; } }
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/"); } } }