protected void btnEdit_Click(object sender, EventArgs e) { Customer OldCustomer = (Customer)Session["customer"]; // Check for empty fields if (Quick.IsEmpty(username, email, displayName, cardNo)) { // There are empty fields lblEditError = FormatLbl.Error("Ensure you do not have empty fields (except for password)."); lblEditError.ID = "lblEditError"; } else { // Check for valid email if (!Quick.CheckRegex(email.Text, @".+\@.+\..+")) { lblEditError = FormatLbl.Error("Email must be valid."); lblEditError.ID = "lblEditError"; } else { if (!ErrorInEdit(OldCustomer)) { string NewPass = OldCustomer.Passwd; byte[] NewSalt = OldCustomer.PasswordSalt; // If password is not empty if (password.Text != String.Empty) { Hasher hash = new Hasher(password.Text); NewPass = hash.GetHashedPassword(); NewSalt = hash.GetSalt(); } string cardNoStr = ""; // If no card number is inserted, make the data null if (cardNo.Text == String.Empty) { cardNoStr = "not given"; } else { cardNoStr = cardNo.Text; } Customer newCustomer = new Customer(OldCustomer.Id, username.Text, displayName.Text, email.Text, NewPass, NewSalt, cardNoStr); CustomerDao dao = new CustomerDao(); dao.Update(newCustomer, OldCustomer.Id); //Update the record based on original ID Session["customer"] = newCustomer; // Update the one in the session Response.Redirect("CustomerAccount.aspx?Edit=Success"); // Refreshes the page } } } }
protected void btnEdit_Click(object sender, EventArgs e) { Artist OldArtist = (Artist)Session["artist"]; // Check for empty fields if (Quick.IsEmpty(username, email, displayName, bio)) { // There are empty fields lblEditError = FormatLbl.Error("Ensure you do not have empty fields (except for password)."); lblEditError.ID = "lblEditError"; } else { // Check for valid email if (!Quick.CheckRegex(email.Text, @".+\@.+\..+")) { lblEditError = FormatLbl.Error("Email must be valid."); lblEditError.ID = "lblEditError"; } else { if (!ErrorInEdit(OldArtist)) { string NewPass = OldArtist.Passwd; byte[] NewSalt = OldArtist.PasswordSalt; // If password is not empty, update password if (password.Text != String.Empty) { Hasher hash = new Hasher(password.Text); NewPass = hash.GetHashedPassword(); NewSalt = hash.GetSalt(); } Artist newArtist = new Artist(OldArtist.Id, username.Text, displayName.Text, email.Text, NewPass, NewSalt, bio.Text); ArtistDao dao = new ArtistDao(); dao.Update(newArtist, OldArtist.Id); //Update the record based on original ID Session["artist"] = newArtist; // Update the one in the session Response.Redirect("ArtistAccount.aspx?Edit=Success"); // Refreshes the page } } } }
private bool FormHasError() { string errorMsg = String.Empty; if (txtCardHolderName.Text == String.Empty || txtCardNo.Text == String.Empty || txtCvv.Text == String.Empty || txtExpDate.Text == String.Empty || txtAddress.Text == String.Empty) { errorMsg = "Ensure all fields are filled in."; } //char[] cardNoChar = txtCardNo.Text.ToCharArray(); /*for (int i = 0; i < cardNoChar.Length; i++) * { * if (!Char.IsDigit(cardNoChar[i])) * errorMsg = "Ensure that Card No. contains only digits"; * }*/ // check the credit card if (!Bank.Validate(txtCardNo.Text, txtCvv.Text, txtExpDate.Text, txtCardHolderName.Text)) // If card is invalid { errorMsg = "Credit Card information is not correct and valid."; } // Check date if (!Quick.CheckRegex(txtExpDate.Text, @"\d\d\/\d\d")) // If expDate is not 00/00 format { errorMsg = "Ensure that Expiry Date is MM/YY format"; } if (errorMsg == String.Empty) { return(false); } else { lblErrorMsg = FormatLbl.Error(errorMsg); return(true); } }