Example #1
0
 public static string ToJsonString(ScoreByCategoryModel model)
 {
     if (model != null)
     {
         return(JsonConvert.SerializeObject(model));
     }
     else
     {
         return(null);
     }
 }
Example #2
0
        public static ScoreByCategoryModel GetScoreByCategory(int crn, int semester, int year)
        {
            ScoreByCategoryModel scoreByCategory = null;
            SqlConnection        connection      = GetConnection();

            string selectStatement = "EXEC ScoreByCategory @crn, @year, @semester";

            SqlCommand command = new SqlCommand(selectStatement, connection);

            command.Parameters.AddWithValue("crn", crn);
            command.Parameters.AddWithValue("semester", semester);
            command.Parameters.AddWithValue("year", year);

            try
            {
                connection.Open();
                SqlDataReader reader = command.ExecuteReader();
                scoreByCategory = new ScoreByCategoryModel();
                while (reader.Read())
                {
                    var data = new ScoreByCategoryModel.Data();
                    data.Average      = Convert.ToDouble(reader["Average"]);
                    data.StandardDev  = Convert.ToDouble(reader["StandardDeviation"].ToString());
                    data.CategoryName = reader["CategoryName"].ToString();
                    data.CategoryID   = Convert.ToInt32(reader["CategoryID"].ToString());
                    data.Questions    = reader["Questions"].ToString();

                    scoreByCategory.DATA.Add(data);
                }

                return(scoreByCategory);
            }

            catch (SqlException ex)
            {
                return(null);
            }


            finally
            {
                connection.Close();
            }
        }