Exemple #1
0
        public ViewFeedbackAdmin()
        {
            this.InitializeComponent();
            CustomerReview cr = new CustomerReview();

            ReviewList.ItemsSource = cr.GetReviews((App.Current as App).ConnectionString);
        }
        public ObservableCollection <CustomerReview> GetReviews(string connectionString)
        {
            const string GetReviewsQuery = "select * from Reviews";
            var          reviews         = new ObservableCollection <CustomerReview>();

            try
            {
                using (SqlConnection conn = new SqlConnection(connectionString))
                {
                    conn.Open();
                    if (conn.State == System.Data.ConnectionState.Open)
                    {
                        using (SqlCommand cmd = conn.CreateCommand())
                        {
                            cmd.CommandText = GetReviewsQuery;
                            using (SqlDataReader reader = cmd.ExecuteReader())
                            {
                                while (reader.Read())
                                {
                                    var review = new CustomerReview();
                                    review.ReviewID  = reader.GetInt32(0);
                                    review.FirstName = reader.GetString(1);
                                    review.LastName  = reader.GetString(2);
                                    review.Email     = reader.GetString(3);
                                    review.Review    = reader.GetString(4);
                                    reviews.Add(review);
                                }
                            }
                        }
                    }
                }
                return(reviews);
            }catch (Exception ex)
            {
                Debug.WriteLine(ex.Message);
            }
            return(null);
        }