Esempio n. 1
0
 public void setup_and_open_Connection_pass_to_gateway_setup_the_dataSet()
 {
     recordingDataSet = new RecordingDataSet();
     gateway = new ArtistGateway(Connection);
     // insert a new artist getting its ID from the database
     artistId = gateway.Insert(recordingDataSet, artistName);
 }
Esempio n. 2
0
        public RecordingDataSet make_sample_recording_with_artist_id_and_label_id_and_insert_into_database(SqlConnection connection)
        {
            RecordingDataSet recordingDataSet = new RecordingDataSet();

            recordingGateway = new RecordingGateway(connection);
            artistGateway = new ArtistGateway(connection);
            labelGateway = new LabelGateway(connection);

            artistId = artistGateway.Insert(recordingDataSet, "Artist");
            labelId = labelGateway.Insert(recordingDataSet, "Label");
            recordingId = recordingGateway.Insert(recordingDataSet, title, releaseDate, artistId, labelId);

            trackGateway = new TrackGateway(connection);
            trackId = trackGateway.Insert(recordingDataSet, "Track", 120);
            RecordingDataSet.Track inMemoryDataset_table_track = trackGateway.FindById(trackId, recordingDataSet);

               // RecordingDataSet rec = new RecordingDataSet();

               // RecordingDataSet.Recording recording = recordingGateway.FindById(recordingId, rec);
               //// // link the sample_recording to the track we just created
               //inMemoryDataset_table_track.Recording = recording;
               //trackGateway.Update(rec);

               // recordingGateway.FindById(recordingId, recordingDataSet);

            return recordingDataSet;
        }
Esempio n. 3
0
        public static RecordingDataSet.Recording FindByRecordingId(RecordingDataSet recordingDataSet, long recordingId)
        {
            SqlConnection connection = null;
            RecordingDataSet.Recording recording = null;
            try
            {
                //connection = new SqlConnection(ConfigurationSettings.AppSettings.Get("Catalog.Connection"));
                connection = new SqlConnection("Data Source=DAVEXPLAPTOP;Initial Catalog=catalog;Integrated Security=True");
                connection.Open();

                RecordingGateway recordingGateway = new RecordingGateway(connection);
                recording = recordingGateway.FindById(recordingId, recordingDataSet);
                if (recording != null)
                {
                    long artistId = recording.ArtistId;
                    ArtistGateway artistGateway = new ArtistGateway(connection);
                    RecordingDataSet.Artist artist = artistGateway.FindById(artistId, recordingDataSet);

                    long labelId = recording.LabelId;
                    LabelGateway labelGateway = new LabelGateway(connection);
                    RecordingDataSet.Label label = labelGateway.FindById(labelId, recordingDataSet);

                    GenreGateway genreGateway = new GenreGateway(connection);
                    TrackGateway trackGateway = new TrackGateway(connection);
                    foreach (RecordingDataSet.Track track in trackGateway.FindByRecordingId(recordingId, recordingDataSet))
                    {
                        artistId = track.ArtistId;
                        long genreId = track.GenreId;
                        artist = artistGateway.FindById(artistId, recordingDataSet);
                        RecordingDataSet.Genre genre = genreGateway.FindById(genreId, recordingDataSet);
                    }

                    ReviewGateway reviewGateway = new ReviewGateway(connection);
                    ReviewerGateway reviewerGateway = new ReviewerGateway(connection);
                    foreach (RecordingDataSet.Review review in reviewGateway.FindByRecordingId(recordingId, recordingDataSet))
                    {
                        long reviewerId = review.ReviewerId;
                        RecordingDataSet.Reviewer reviewer = reviewerGateway.FindById(reviewerId, recordingDataSet);
                    }
                }
            }
            finally
            {
                if (connection != null)
                    connection.Close();
            }
            return recording;
        }
Esempio n. 4
0
        public void SetUp_a_known_recording_then_verify_it_brings_back_the_same_data()
        {
            recordingDataSet = new RecordingDataSet();

            recordingGateway = new RecordingGateway(Connection);
            trackGateway = new TrackGateway(Connection);
            reviewGateway = new ReviewGateway(Connection);
            reviewerGateway = new ReviewerGateway(Connection);
            labelGateway = new LabelGateway(Connection);
            artistGateway = new ArtistGateway(Connection);
            genreGateway = new GenreGateway(Connection);

            artistId = artistGateway.Insert(recordingDataSet, "Artist");
            labelId = labelGateway.Insert(recordingDataSet, "Label");
            genreId = genreGateway.Insert(recordingDataSet, "Genre");
            reviewerId = reviewerGateway.Insert(recordingDataSet, "Reviewer");
            recordingId = recordingGateway.Insert(recordingDataSet, "Recording Title", new DateTime(1999, 1, 12), artistId, labelId);
            reviewId = reviewGateway.Insert(recordingDataSet, 1, "Review");

            trackId1 = trackGateway.Insert(recordingDataSet, "Track Title", 120);
            trackId2 = trackGateway.Insert(recordingDataSet, "Track Title", 130);

            RecordingDataSet.Recording recording = recordingGateway.FindById(recordingId, recordingDataSet);
            RecordingDataSet.Review review = reviewGateway.FindById(reviewId, recordingDataSet);
            RecordingDataSet.Track track1 = trackGateway.FindById(trackId1, recordingDataSet);
            RecordingDataSet.Track track2 = trackGateway.FindById(trackId2, recordingDataSet);
            RecordingDataSet.Label label = labelGateway.FindById(labelId, recordingDataSet);
            RecordingDataSet.Genre genre = genreGateway.FindById(genreId, recordingDataSet);
            RecordingDataSet.Artist artist = artistGateway.FindById(artistId, recordingDataSet);
            RecordingDataSet.Reviewer reviewer = reviewerGateway.FindById(reviewerId, recordingDataSet);

            // setup the relationships
            recording.Artist = artist;
            recording.Label = label;
            track1.Recording = recording;
            track1.Artist = artist;
            track1.Genre = genre;

            track2.Recording = recording;
            track2.Artist = artist;
            track2.Genre = genre;

            review.Recording = recording;
            review.Reviewer = reviewer;

            // only these as they are in the 'middle' and depend??
            recordingGateway.Update(recordingDataSet);
            trackGateway.Update(recordingDataSet);
            reviewGateway.Update(recordingDataSet);

            RecordingDataSet loadedDataSet = new RecordingDataSet();
            loadedRecording = Catalog.FindByRecordingId(loadedDataSet, recordingId);
        }