Exemple #1
0
        public static RecordingDataSet.Review AddReview(RecordingDataSet dataSet,
                                                        string name, string content, int rating, long recordingId)
        {
            SqlConnection connection = null;

            RecordingDataSet.Review review = null;

            try
            {
                connection = new SqlConnection(
                    ConfigurationSettings.AppSettings.Get("Catalog.Connection"));
                connection.Open();

                RecordingDataSet.Recording recording =
                    FindByRecordingId(dataSet, recordingId);

                ReviewerGateway reviewerGateway =
                    new ReviewerGateway(connection);

                RecordingDataSet.Reviewer reviewer =
                    reviewerGateway.FindByName(name, dataSet);

                if (reviewer == null)
                {
                    long reviewerId = reviewerGateway.Insert(dataSet, name);
                    reviewer = reviewerGateway.FindById(reviewerId, dataSet);
                }

                foreach (RecordingDataSet.Review existingReview in
                         recording.GetReviews())
                {
                    if (existingReview.Reviewer.Name.Equals(name))
                    {
                        throw new ExistingReviewException(existingReview.Id);
                    }
                }

                ReviewGateway reviewGateway = new ReviewGateway(connection);
                long          reviewId      = reviewGateway.Insert(dataSet, rating, content);

                review            = reviewGateway.FindById(reviewId, dataSet);
                review.ReviewerId = reviewer.Id;
                review.Recording  = recording;
                reviewGateway.Update(dataSet);
            }
            finally
            {
                if (connection != null)
                {
                    connection.Close();
                }
            }

            return(review);
        }
            public void Execute()
            {
                SqlConnection connection =
                    TransactionManager.Transaction().Connection;

                RecordingDataSet.Recording recording =
                    FindByRecordingId(dataSet, recordingId);

                ReviewerGateway reviewerGateway =
                    new ReviewerGateway(connection);

                RecordingDataSet.Reviewer reviewer =
                    reviewerGateway.FindByName(name, dataSet);

                if (reviewer == null)
                {
                    long reviewerId = reviewerGateway.Insert(dataSet, name);
                    reviewer = reviewerGateway.FindById(reviewerId, dataSet);
                }

                foreach (RecordingDataSet.Review existingReview in recording.GetReviews())
                {
                    if (existingReview.Reviewer.Name.Equals(name))
                    {
                        throw new ExistingReviewException(existingReview.Id);
                    }
                }

                ReviewGateway reviewGateway = new ReviewGateway(connection);
                long          reviewId      = reviewGateway.Insert(dataSet, rating, content);

                review = reviewGateway.FindById(reviewId, dataSet);

                review.ReviewerId = reviewer.Id;
                review.Recording  = recording;
                reviewGateway.Update(dataSet);
            }