public void InsertAlbum([RouteData] int? artistId) { var item = new Album(); item.ArtistID = artistId; if (TryUpdateModel(item)) { try { Service.SaveAlbum(item); try { var picUpload = FormView.FindControl("PicUpload") as FileUpload; Service.SaveAlbumArt(picUpload.FileContent, item.AlbumID); this.SetTempData("SuccessMessage", "The album was created."); Response.RedirectToRoute("AlbumDetails", new {id = item.AlbumID}); Context.ApplicationInstance.CompleteRequest(); } catch { ModelState.AddModelError(String.Empty, "Error while saving the album picture"); } } catch { ModelState.AddModelError(String.Empty, "Error while adding the album to the database"); } } }
/// <summary> /// Save the album /// </summary> public static void SaveAlbum(Album album) { if (!album.Validate()) { throw new ValidationException(); } if (album.AlbumID == 0) { AlbumDAL.InsertAlbum(album); } else { AlbumDAL.UpdateAlbum(album); } }