public TravellerProfile SelectByEmail(string email) { string DBConnect = ConfigurationManager.ConnectionStrings["ConnStr"].ConnectionString; SqlConnection myConn = new SqlConnection(DBConnect); string sqlstmt = "SELECT * From Travellers where Email = @paraEmail"; SqlDataAdapter da = new SqlDataAdapter(sqlstmt, myConn); da.SelectCommand.Parameters.AddWithValue("@paraEmail", email); DataSet ds = new DataSet(); da.Fill(ds); TravellerProfile user = null; int rec_cnt = ds.Tables[0].Rows.Count; if (rec_cnt == 1) { DataRow row = ds.Tables[0].Rows[0]; int id = Convert.ToInt32(row["UserId"]); string name = row["Username"].ToString(); string Email = row["Email"].ToString(); string password = row["Password"].ToString(); string foodpref = row["FoodPref"].ToString(); string language = row["Language"].ToString(); string style = row["Style"].ToString(); int isHost = Convert.ToInt32(row["IsHost"]); user = new TravellerProfile(id, name, password, Email, foodpref, language, style, isHost); } return(user); }
public int UpdateProfile(TravellerProfile tv) { string DBConnect = ConfigurationManager.ConnectionStrings["ConnStr"].ConnectionString; SqlConnection myConn = new SqlConnection(DBConnect); string sqlStmt = "UPDATE Travellers SET Username = @parauname, Email = @paramail, Language = @paralang, FoodPref = @parafp, Style = @parasty where UserId = @parauserid"; int result = 0; // Execute NonQuery return an integer value SqlCommand sqlCmd = new SqlCommand(sqlStmt, myConn); sqlCmd = new SqlCommand(sqlStmt.ToString(), myConn); sqlCmd.Parameters.AddWithValue("@parauserid", tv.ID); sqlCmd.Parameters.AddWithValue("@parauname", tv.Name); sqlCmd.Parameters.AddWithValue("@paramail", tv.Email); sqlCmd.Parameters.AddWithValue("@paralang", tv.Language); sqlCmd.Parameters.AddWithValue("@parafp", tv.FoodPref); sqlCmd.Parameters.AddWithValue("@parasty", tv.Style); myConn.Open(); result = sqlCmd.ExecuteNonQuery(); myConn.Close(); return(result); }
public TravellerProfile SelectById(int ID) { string DBConnect = ConfigurationManager.ConnectionStrings["ConnStr"].ConnectionString; SqlConnection myConn = new SqlConnection(DBConnect); string sqlstmt = "Select * from Travellers where UserId = @paraId"; SqlDataAdapter da = new SqlDataAdapter(sqlstmt, myConn); da.SelectCommand.Parameters.AddWithValue("@paraId", ID); DataSet ds = new DataSet(); da.Fill(ds); int rec_cnt = ds.Tables[0].Rows.Count; TravellerProfile tv = null; if (rec_cnt > 0) { DataRow row = ds.Tables[0].Rows[0]; int id = Convert.ToInt32(row["UserId"]); string name = row["Username"].ToString(); string email = row["Email"].ToString(); string foodpref = row["FoodPref"].ToString(); string language = row["Language"].ToString(); string style = row["Style"].ToString(); tv = new TravellerProfile(id, name, email, foodpref, language, style); } return(tv); }
protected void Page_Load(object sender, EventArgs e) { if (IsPostBack == false) { if (Session["UserID"] != null) // means not logged in, but masterpage page_load will handle and kick user back to login { int id = Convert.ToInt32(Session["UserID"]); TravellerProfile tp = new TravellerProfile(); tp = tp.RetrieveOne(id); if (tp != null) { username.Text = tp.Name; uemail.Text = tp.Email; lang.SelectedValue = tp.Language.ToString(); travelstyle.SelectedValue = tp.Style.ToString(); foodpref.SelectedValue = tp.FoodPref.ToString(); travelstyle.SelectedValue = tp.Style.ToString(); } else { Response.Redirect("Login.aspx"); } } else { Response.Redirect("Login.aspx"); } } }
protected void btnLogin_Click(object sender, EventArgs e) { string email = emailTB.Text; string password = passwordTB.Text; lblError.Text = String.Empty; if (email == "") { lblError.Text += "Email is required <br>"; lblError.ForeColor = Color.Red; } if (password == "") { lblError.Text += "Password is required <br>"; lblError.ForeColor = Color.Red; } else { TravellerProfile user = new TravellerProfile(); user = user.GetbyEmail(emailTB.Text); if (user != null) { if (passwordTB.Text == user.Password) { Session["Username"] = user.Name.ToString(); Session["Email"] = user.Email.ToString(); Session["UserID"] = user.ID.ToString(); Session["isHost"] = user.isHost.ToString(); lblsuccess.Text = "Login Success"; lblsuccess.ForeColor = Color.Green; if (emailTB.Text == "*****@*****.**") { Response.Redirect("../Home/AdminHomepage.aspx"); } else { Response.Redirect("../Home/UserHomepage.aspx"); } } else { lblError.Text = "Incorrect Password"; lblError.ForeColor = Color.Red; } } else { lblError.Text = "Incorrect Email/Password"; lblError.ForeColor = Color.Red; } } }
protected void btnSubmit_Click(object sender, EventArgs e) { if (Convert.ToString(Session["Email"]) == HEmail.Text) { if (HostRequired.Checked == true) { int id = Convert.ToInt32(Session["UserID"]); string Email = HEmail.Text; //string Desc = HDesc.Text; //string Reason = HReasons.Text; //TravellerProfile tp = new TravellerProfile(id, Email, Desc, Reason); TravellerProfile tp = new TravellerProfile(Email); int result = tp.HostApproval(); if (result == 1) { LblMsg.Text = "Successfully signed up as a Host!"; LblMsg.ForeColor = System.Drawing.Color.Green; Session["isHost"] = tp.isHost.ToString(); HEmail.Text = ""; //HDesc.Text = ""; //HReasons.Text = ""; } else { LblMsg.Text = "An error occured. Please try again"; LblMsg.ForeColor = System.Drawing.Color.Red; } } else { LblMsg.Text = "Please tick the Accept Host Terms checkbox!"; LblMsg.ForeColor = System.Drawing.Color.Red; } } else { LblMsg.Text = "Email entered is not the same as your user email!"; LblMsg.ForeColor = System.Drawing.Color.Red; } }
/*public int UpdateHostInfo(TravellerProfile tv) * { * string DBConnect = ConfigurationManager.ConnectionStrings["ConnStr"].ConnectionString; * SqlConnection myConn = new SqlConnection(DBConnect); * * string sqlStmt = "UPDATE Travellers SET Email = @paramail, Description = @parahdesc, Reason = @parahreason where UserId = @parauserid"; * * int result = 0; // Execute NonQuery return an integer value * SqlCommand sqlCmd = new SqlCommand(sqlStmt, myConn); * * * sqlCmd = new SqlCommand(sqlStmt.ToString(), myConn); * * sqlCmd.Parameters.AddWithValue("@parauserid", tv.ID); * sqlCmd.Parameters.AddWithValue("@paramail", tv.Email); * sqlCmd.Parameters.AddWithValue("@parahdesc", tv.Description); * sqlCmd.Parameters.AddWithValue("@parahreason", tv.Reason); * * myConn.Open(); * result = sqlCmd.ExecuteNonQuery(); * * myConn.Close(); * * return result; * }*/ public int UpdateHostInfo(TravellerProfile tv) { string DBConnect = ConfigurationManager.ConnectionStrings["ConnStr"].ConnectionString; SqlConnection myConn = new SqlConnection(DBConnect); string sqlStmt = "UPDATE Travellers SET isHost = 1 where Email = @paramail"; int result = 0; // Execute NonQuery return an integer value SqlCommand sqlCmd = new SqlCommand(sqlStmt, myConn); sqlCmd = new SqlCommand(sqlStmt.ToString(), myConn); sqlCmd.Parameters.AddWithValue("@paramail", tv.Email); myConn.Open(); result = sqlCmd.ExecuteNonQuery(); myConn.Close(); return(result); }
protected void btnSubmit_Click(object sender, EventArgs e) { string pass = password.Text; string cfm = cfmpass.Text; int id = Convert.ToInt32(Session["UserID"]); TravellerProfile tv = new TravellerProfile(); int rslt = tv.ChangePassword(id, pass); if (rslt == 1) { lblMsg.Text = "Successfully changed password!"; lblMsg.ForeColor = System.Drawing.Color.Green; } else { lblMsg.Text = "An error occured while changing your password. Please try again!"; lblMsg.ForeColor = System.Drawing.Color.Red; } password.Text = ""; cfmpass.Text = ""; }
protected void btnUpdate_Click(object sender, EventArgs e) { int id = Convert.ToInt32(Session["UserID"]); string Uname = username.Text; string Email = uemail.Text; string FoodPref = foodpref.SelectedItem.ToString(); string Language = lang.SelectedItem.ToString(); string style = travelstyle.SelectedItem.ToString(); TravellerProfile tp = new TravellerProfile(id, Uname, Email, FoodPref, Language, style); int rslt = tp.UpdateProifle(); if (rslt == 1) { lblMsg.Text = "Update successful!"; lblMsg.ForeColor = System.Drawing.Color.Green; } else { lblMsg.Text = "An error occured while updating your profile. Please try again"; lblMsg.ForeColor = System.Drawing.Color.Red; } }