Esempio n. 1
0
        /*************************************************************
         * Views all Reviews with the stored procedure.
         * Returns a list of students to show in an index
         ************************************************************/
        public List <Review> GetReviews()
        {
            Connection();
            List <Review> reviewlist = new List <Review>();

            SqlCommand cmd = new SqlCommand("Project.GetAllReviews", con)
            {
                CommandType = CommandType.StoredProcedure
            };
            SqlDataAdapter sd = new SqlDataAdapter(cmd);
            DataTable      dt = new DataTable();

            ClassDBHandle classDBHandle = new ClassDBHandle();

            con.Open();
            sd.Fill(dt);
            con.Close();

            foreach (DataRow dr in dt.Rows)
            {
                reviewlist.Add(
                    new Review
                {
                    ReviewId    = Convert.ToInt32(dr["ReviewId"]),
                    ClassId     = Convert.ToInt32(dr["ClassId"]),
                    ClassName   = Convert.ToString(dr["ClassName"]),
                    ScreenName  = Convert.ToString(dr["ScreenName"]),
                    Description = Convert.ToString(dr["Description"]),
                    Rating      = Convert.ToInt32(dr["Rating"])
                });
            }
            return(reviewlist);
        }
Esempio n. 2
0
        /*************************************************************
         * Shows a Review's details with the stored procedure.
         * Returns the particular student to show
         ************************************************************/
        public Review GetReviewDetails(int id)
        {
            Connection();
            Review review = new Review();

            SqlCommand cmd = new SqlCommand("Project.GetReviewDetails", con)
            {
                CommandType = CommandType.StoredProcedure
            };

            cmd.Parameters.AddWithValue("@ReviewId", id);

            SqlDataAdapter sd = new SqlDataAdapter(cmd);
            DataTable      dt = new DataTable();

            ClassDBHandle classDBHandle = new ClassDBHandle();

            con.Open();
            sd.Fill(dt);
            con.Close();

            if (dt.Rows.Count > 0)
            {
                DataRow dr = dt.Rows[0];

                return(new Review
                {
                    ReviewId = Convert.ToInt32(dr["ReviewId"]),
                    ClassId = Convert.ToInt32(dr["ClassId"]),
                    ClassName = Convert.ToString(dr["ClassName"]),
                    ScreenName = Convert.ToString(dr["ScreenName"]),
                    Description = Convert.ToString(dr["Description"])
                });
            }
            else
            {
                return(null);
            }
        }