Beispiel #1
0
 /// <summary>
 /// Adds a new album into the database
 /// </summary>
 /// <param name="newAlbumDTO">Album info needed to create new album into database</param>
 /// <returns>Unique Id of album created</returns>
 public Guid AddNewAlbumToDatabase(NewAlbumDTO newAlbumDTO)
 {
     using (var db = new SqlConnection(_connectionString))
     {
         var sql = @"INSERT INTO [Album]
                     (
                         [Title],
                         [ImgUrl],
                         [Label],
                         [Artist],
                         [ReleaseYear],
                         [DiscogId]
                     )
                     OUTPUT INSERTED.Id
                     VALUES
                     (
                         @title,
                         @imgUrl,
                         @label,
                         @artist,
                         @releaseYear,
                         @discogId
                     )";
         var id  = db.QueryFirst <Guid>(sql, newAlbumDTO);
         foreach (string genreName in newAlbumDTO.Genre)
         {
             _genreRepo.AddGenreToAlbum(id, genreName);
         }
         return(id);
     }
 }