public string EditAlbum(string form, string fileStream, string fileName, string fileType) { var result = "The album was not created. Please try again. If the problem persists, please contact us at [email protected]"; var formCollection = form.Split('&'); var trmservice = new WebService.WCFWebServiceJson(); var artist = trmservice.GetArtist(WebSecurity.CurrentUserId); var util = new Utilities(); var localFile = Path.Combine(MusicManagerBase.LocalTempDestinationPath, fileName); if (!string.IsNullOrEmpty(fileStream)) { byte[] bytes = Convert.FromBase64String(fileStream); using (MemoryStream ms = new MemoryStream(bytes)) { Image image = Image.FromStream(ms); image.Save(localFile); } } // populate the list of albums for this artist to be displayed in the management section ViewBag.ArtistAlbums = trmservice.GetArtistAlbums(artist); if (!string.IsNullOrEmpty(fileName) || !string.IsNullOrEmpty(MusicManagerBase.ReturnFormItemValue(formCollection, "AlbumCoverPath"))) { // Attempt to save the album try { var albumGenreList = new List<Genre>(); foreach (var formItem in formCollection) { if (formItem.ToString().StartsWith("genre")) { albumGenreList.Add(new Genre { GenreId = GetGenreId(formItem.ToString()), GenreName = GetGenreName(formItem.ToString()) }); } } var albumId = 0; if (!string.IsNullOrEmpty(MusicManagerBase.ReturnFormItemValue(formCollection, "AlbumId")) && Convert.ToInt32(MusicManagerBase.ReturnFormItemValue(formCollection, "AlbumId")) > 0) { albumId = Convert.ToInt32(MusicManagerBase.ReturnFormItemValue(formCollection, "AlbumId")); trmservice.UpdateAlbumGenreCollection(albumId, albumGenreList); } // if editing, if no image is uploaded, use the existing path var albumCover = string.Empty; if (string.IsNullOrEmpty(fileName)) { albumCover = MusicManagerBase.ReturnFormItemValue(formCollection, "AlbumCoverPath"); } else { albumCover = util.RemoveSpaces(artist.ArtistName) + "/" + util.RemoveSpaces(MusicManagerBase.ReturnFormItemValue(formCollection, "AlbumTitle")) + "/" + fileName; } var releaseDate = MusicManagerBase.ReturnFormItemValue(formCollection, "AlbumReleaseDate").ToString().Replace("%2F", "/"); var album = new Album { AlbumId = albumId, AlbumTitle = MusicManagerBase.ReturnFormItemValue(formCollection, "AlbumTitle"), AlbumProducer = MusicManagerBase.ReturnFormItemValue(formCollection, "AlbumProducer"), AlbumLabel = MusicManagerBase.ReturnFormItemValue(formCollection, "AlbumLabel"), AlbumReleaseDate = Convert.ToDateTime(releaseDate), AlbumCover = albumCover, GenreCollection = albumGenreList, CreatedDate = DateTime.Now }; // link the album to the artist and save it trmservice.SaveArtistAlbum(album, artist, localFile); result = "You have successfully uploaded the album " + album.AlbumTitle; } catch (MembershipCreateUserException e) { result = ErrorCodeToString(e.StatusCode); } } else { result = "Please select an album cover"; } // delete the temp file if (System.IO.File.Exists(localFile)) { System.IO.File.Delete(localFile); } return result; }