private void LoadAlbumUrls(Album album)
        {
            MsSql db = new MsSql(_connectionString);
              SqlCommand command = db.GetNewCommand("GetAlbumUrls", CommandType.StoredProcedure);

              try
              {
            command.Parameters.Add("@AlbumId", SqlDbType.BigInt).Value = album.Id;
            db.AddErrorHandlingParamsToSqlCommand(command);

            SqlDataReader reader = command.ExecuteReader();
            try
            {
              int ordId = reader.GetOrdinal("Id");
              int ordDisplayText = reader.GetOrdinal("DisplayText");
              int ordUrl = reader.GetOrdinal("Url");

              while (reader.Read())
              {
            album.ListenUrls.Add(new DynamicUrl()
            {
              DisplayText = reader.GetString(ordDisplayText),
              Url = reader.GetString(ordUrl)
            });
              }
            }
            finally
            {
              reader.Close();
            }

            db.FreeCommand(command);
              }
              catch (Exception ex)
              {
            db.FreeCommand(command, false);
            throw ex;
              }
        }
예제 #2
0
 public ViewAlbum()
 {
     Album = new Album();
       ImageRelativeDirPath = string.Empty;
 }
        private void LoadPodcastAlbums(PodcastArticle article)
        {
            MsSql db = new MsSql(_connectionString);
              SqlCommand command = db.GetNewCommand("GetPodcastAlbums", CommandType.StoredProcedure);

              try
              {
            command.Parameters.Add("@ArticleId", SqlDbType.BigInt).Value = article.Id;
            db.AddErrorHandlingParamsToSqlCommand(command);

            SqlDataReader reader = command.ExecuteReader();
            try
            {
              int ordId = reader.GetOrdinal("Id");
              int ordArtist = reader.GetOrdinal("Artist");
              int ordCaption = reader.GetOrdinal("Caption");
              int ordCoverImageFileName = reader.GetOrdinal("CoverImageFileName");
              int ordLabel = reader.GetOrdinal("Label");
              int ordTitle = reader.GetOrdinal("Title");
              int ordYear = reader.GetOrdinal("Year");

              const int EXPECTED_ALBUM_COUNT = 2;
              int albumCount = 0;
              while (reader.Read())
              {
            //Increment our album counter
            albumCount++;

            //Make sure that we haven't surpassed the expected album count
            if (albumCount > EXPECTED_ALBUM_COUNT)
              throw new PodcastAlbumCountException(albumCount, EXPECTED_ALBUM_COUNT);

            Album newAlbum = new Album()
            {
              Artist = reader.GetString(ordArtist),
              Caption = reader.GetString(ordCaption),
              CoverImageFileName = reader.GetString(ordCoverImageFileName),
              Id = reader.GetInt64(ordId),
              Label = reader.GetString(ordLabel),
              Title = reader.GetString(ordTitle),
              Year = reader.GetInt32(ordYear)
            };

            //Get listen URLs for the album
            LoadAlbumUrls(newAlbum);

            //Assign the album to the provided article
            if (albumCount == 1)
            {
              //Podcast album #1
              article.Album1 = newAlbum;
            }
            else
            {
              //Podcast album #2
              article.Album2 = newAlbum;
            }
              }

              if (albumCount != EXPECTED_ALBUM_COUNT)
            throw new PodcastAlbumCountException(albumCount, EXPECTED_ALBUM_COUNT);
            }
            finally
            {
              reader.Close();
            }

            db.FreeCommand(command);
              }
              catch (Exception ex)
              {
            db.FreeCommand(command, false);
            throw ex;
              }
        }