protected void ValidateDetails() { if (!string.IsNullOrEmpty(Request["UserName"]) && !string.IsNullOrEmpty(Request["UserPassword"])) { DBManipulationsLogic dbLogic = new DBManipulationsLogic(); UserPersonalDetails user = new UserPersonalDetails { UserName = Request["UserName"], UserPassword = Request["UserPassword"] }; var UserId = dbLogic.UserNameExists(new UserLoginDetails { UserName = Request["UserName"], UserPassword = Request["UserPassword"] }, true); dbLogic.Dispose(); if (UserId != null) { Session["UserId"] = UserId; Session["IsUserLoggedIn"] = true; Response.Redirect("Products.aspx"); } else { HttpCookie LoginErrorCookie = Request.Cookies.Get("LoginError"); LoginErrorCookie.Value = "True"; HttpCookie LoginErrorMessageCookie = Request.Cookies.Get("LoginErrorMessage"); LoginErrorMessageCookie.Value = "Invalid Login Details Provided."; } } }
protected void Page_Load(object sender, EventArgs e) { if (Session["IsUserLoggedIn"] != null && Session["IsUserLoggedIn"] as bool? != false && Session["UserId"] != null) { DBManipulationsLogic db = new DBManipulationsLogic(); if (Request.QueryString["UpdatedVal"] != null) { //Convert Json Array to int Array JavaScriptSerializer js = new JavaScriptSerializer(); int[] ProductIds = js.Deserialize <int[]>(Request.QueryString["UpdatedVal"].ToString()); db.UpdateUserCart(Session["UserId"] as int?, ProductIds); } PopulateViewStateValue(db); if (Page.IsPostBack) { if (Request.QueryString["searchBar"] != null) { Session["Products"] = db.BuildProducts(Session["UserId"] as int?, Request.QueryString["searchBar"].ToString()); } } else { Session["Products"] = db.BuildProducts(Session["UserId"] as int?); Session["ProductListInCart"] = db.BuildProductsInCart(Session["UserId"].ToString()); } } else { Response.Redirect("Home.aspx"); } }
private void PopulateViewStateValue(DBManipulationsLogic db) { UserPersonalDetails user = db.GetUserDetails(Session["UserId"] as int?); UpdateFirstName.Text = user.FirstName; UpdateLastName.Text = user.LastName; UpdateMobileNumber.Text = user.MobileNumber.ToString(); }
protected void UpdateButton_Click(object sender, EventArgs e) { string updatedFirstName = UpdateFirstName.Text.ToString(); string updatedLastName = UpdateLastName.Text.ToString(); int updatedMobileNumber = Convert.ToInt32(UpdateMobileNumber.Text.ToString()); UserPersonalDetails user = new UserPersonalDetails { UserId = Session["UserId"] as int?, FirstName = updatedFirstName, LastName = updatedLastName, MobileNumber = updatedMobileNumber }; DBManipulationsLogic db = new DBManipulationsLogic(); db.UpdateUserInfo(user); }
protected void ValidateDetails() { if (!string.IsNullOrEmpty(Request["UserName"]) && !string.IsNullOrEmpty(Request["UserPassword"])) { DBManipulationsLogic dbLogic = new DBManipulationsLogic(); UserPersonalDetails user = new UserPersonalDetails { UserName = Request["UserName"], UserPassword = Request["UserPassword"], Email = Request["Email"], Address = Request["Address"], MobileNumber = Convert.ToInt64(Request["MobileNumber"]), Gender = Convert.ToChar(Request["SelectedRadioGender"]), ProfessionId = Convert.ToInt32(Request["SelectedDropDownOccupation"]), FirstName = Request["FirstName"], LastName = Request["LastName"], }; if (dbLogic.UserNameExists(new UserLoginDetails { UserName = Request["UserName"], UserPassword = Request["UserPassword"] }) == null) { //if username dont exist in the db, insert into db Session["UserId"] = dbLogic.WriteToDB(user); dbLogic.Dispose(); Session["IsUserLoggedIn"] = true; Response.Redirect("Products.aspx"); } else { HttpCookie LoginErrorCookie = Request.Cookies.Get("LoginError"); LoginErrorCookie.Value = "True"; HttpCookie LoginErrorMessageCookie = Request.Cookies.Get("LoginErrorMessage"); LoginErrorMessageCookie.Value = "Username is already in use"; } } }