protected void UpdateAlbum_Click(object sender, EventArgs e) { if (IsValid) { //any other business rules if (string.IsNullOrEmpty(AlbumID.Text)) { MessageUserControl2.ShowInfo("Missing Data", "Missing Album Id. Use Find to locate the album you wish to maintain."); } else { int albumid = 0; if (int.TryParse(AlbumID.Text, out albumid)) { MessageUserControl2.TryRun(() => { AlbumController sysmgr = new AlbumController(); Album newalbum = new Album(); newalbum.AlbumId = albumid; newalbum.Title = AlbumTitle.Text; newalbum.ArtistId = int.Parse(ArtistList.SelectedValue); newalbum.ReleaseYear = int.Parse(AlbumReleaseYear.Text); newalbum.ReleaseLabel = string.IsNullOrEmpty(AlbumReleaseLabel.Text) ? null : AlbumReleaseYear.Text; sysmgr.Albums_Update(newalbum); }, "Update Album", "Album has been successfully update on the database."); } else { MessageUserControl2.ShowInfo("Invalid Data", "Album Id. Use Find to locate the album you wish to maintain."); } } } }
protected void Update_Click(object sender, EventArgs e) { if (string.IsNullOrEmpty(AlbumID.Text)) { Message.Text = "Look up an album to edit."; } else { try { Album item = new Album(); item.AlbumId = int.Parse(AlbumID.Text); item.Title = AlbumTitle.Text; item.ArtistId = int.Parse(ArtistList.SelectedValue); item.ReleaseYear = int.Parse(ReleaseYear.Text); item.ReleaseLabel = string.IsNullOrEmpty(ReleaseLabel.Text) ? null : ReleaseLabel.Text; AlbumController sysmgr = new AlbumController(); int rowsaffected = sysmgr.Albums_Update(item); if (rowsaffected == 0) { Message.Text = "Update had a problem. Album not found."; } else { Message.Text = "Update successful."; SearchResults.DataBind(); } } catch (Exception ex) { Message.Text = ex.Message; } } }