コード例 #1
0
        public List <TvSerieReview> GetAllTvSerieReviewByUserId(int id)
        {
            using (SqlConnection connection = new SqlConnection(connectionString))
            {
                SqlCommand cmd = new SqlCommand("Select * From [dbo].[TvSerieReview], [dbo].[TvSerie] WHERE TvSerieReview.userId = @id AND TvSerieReview.tvSerieId = TvSerie.id", connection);
                connection.Open();

                cmd.Parameters.AddWithValue("id", id);
                var reader = cmd.ExecuteReader();

                List <TvSerieReview> tvSerieReviews = new List <TvSerieReview>();

                while (reader.Read())
                {
                    TvSerieReview tvr = new TvSerieReview()
                    {
                        ReviewId = reader.GetInt32(0),
                        Thoughts = reader.GetString(1),
                        Score    = reader.GetInt32(2),
                        TvSerie  = new TvSerie()
                        {
                            ItemID        = reader.GetInt32(3),
                            ItemName      = reader.GetString(6),
                            Picture       = reader.GetString(7),
                            Genre         = reader.GetString(8),
                            Seasons       = reader.GetInt32(9),
                            EpisodeLength = reader.GetInt32(10)
                        }
                    };
                    tvSerieReviews.Add(tvr);
                }
                return(tvSerieReviews);
            };
        }
コード例 #2
0
        public void CreateTvSerieReview(string thoughts, int score, int tvSerieId, int userId)
        {
            TvSerieReview tsr = new TvSerieReview
            {
                Thoughts = thoughts,
                Score    = score
            };
            TvSerie t = new TvSerie
            {
                ItemID = tvSerieId
            };

            tsr.TvSerie = t;

            rda.CreateTvSerieReview(tsr, userId);
        }
コード例 #3
0
 public void CreateTvSerieReview(TvSerieReview tsr, int userId)
 {
     using (SqlConnection connection = new SqlConnection(connectionString))
     {
         connection.Open();
         using (SqlCommand cmd = connection.CreateCommand())
         {
             cmd.CommandText = "Insert Into [dbo].[TvSerieReview](thoughts, score, tvSerieId, userId) values(@thoughts, @score, @tvSerieId, @userId)";
             cmd.Parameters.AddWithValue("thoughts", tsr.Thoughts);
             cmd.Parameters.AddWithValue("score", tsr.Score);
             cmd.Parameters.AddWithValue("tvSerieId", tsr.TvSerie.ItemID);
             cmd.Parameters.AddWithValue("userId", userId);
             cmd.ExecuteNonQuery();
         }
         connection.Close();
     }
 }