public void Put(int id, [FromBody] Artist artist) { if (artistDao.FindById(id) != null && ModelState.IsValid) { artistDao.Update(artist); } }
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 } } } }