コード例 #1
0
        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
                    }
                }
            }
        }
コード例 #2
0
        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
                    }
                }
            }
        }