public static bool addAlbumGo(string albumTitle, Artist artist, int albumRating, string year, List <TrackInfo> tracks, out string message) { //Verify Album input fields, then add the Album and all associated tracks to the model. bool isValid = true; message = ""; int yr = 0; int doesAlbumExist = CDCatalogManager.GetAlbums().Where(a => a.AlbumTitle.Equals(albumTitle)).Where(a => a.ArtistID.Equals(artist.ArtistID)).Count(); if (!(doesAlbumExist == 0)) { isValid = false; message += "An album by this artist with this title already exists in the database.\n"; } if (!int.TryParse(year, out yr)) { isValid = false; message += "Year must be an integer.\n"; } if (isValid) { Song song = new Song(); Album album = new Album(); album.AlbumTitle = albumTitle; album.ArtistID = artist.ArtistID; album.Rating = albumRating; album.Year = yr; CDCatalogManager.AddAlbum(album); foreach (TrackInfo t in tracks) { song = new Song(); song.AlbumID = album.AlbumID; song.ArtistID = t.artist.ArtistID; song.GenreID = t.genreID; song.Rating = t.rating; song.SongTitle = t.title; song.TrackLength = t.tracklength; song.TrackNumber = t.tracknum; CDCatalogManager.AddSong(song); } } return(isValid); }
public static bool AddSongGo(string title, Artist artist, Album album, string trackIn, Genre genre, string minutes, string seconds, int rating, out string message) { //Validate the input fields from the AddSong window, then add the Song to the model. bool isValid = true; message = ""; int tracknum = 0; int trackminutes = 0; int trackseconds = 0; int doesSongExist = CDCatalogManager.GetSongs().Where(s => s.SongTitle.Equals(title)).Where( s => s.AlbumID.Equals(album.AlbumID)).Where( s => s.ArtistID.Equals(artist.ArtistID)).Count(); if (doesSongExist != 0) { isValid = false; message += "A Song by this Artist on this Album already exists in the database."; } if (title == "") { isValid = false; message += "Song Title cannot be blank.\n"; } if (null == artist) { isValid = false; message += "Please select an Artist.\n"; } if (null == album) { isValid = false; message += "Please select an Album.\n"; } if (!int.TryParse(trackIn, out tracknum) || tracknum < 0) { isValid = false; message += "Track # must be a nonnegative integer.\n"; } if (null == genre) { isValid = false; message += "Please select a Genre.\n"; } if (minutes != "") { if (!int.TryParse(minutes, out trackminutes) || trackminutes < 0) { isValid = false; message += "Track minutes must be a nonnegative integer or blank.\n"; } } if (!int.TryParse(seconds, out trackseconds) || trackseconds < 1) { isValid = false; message += "Track seconds must be a positive integer.\n"; } if (isValid) { Song song = new Song(); song.SongTitle = title; song.ArtistID = artist.ArtistID; song.AlbumID = album.AlbumID; song.TrackNumber = tracknum; song.GenreID = genre.GenreID; song.TrackLength = ((trackminutes * 60) + trackseconds); song.Rating = rating; CDCatalogManager.AddSong(song); } return(isValid); }