public static string ToJsonString(CrnStatisticsModel model) { if (model != null) { return(JsonConvert.SerializeObject(model)); } else { return(null); } }
public static CrnStatisticsModel GetCrnStatistics(int crn, int semester, int year) { CrnStatisticsModel crnStatistics = null; SqlConnection connection = GetConnection(); string selectStatement = "EXEC CrnStatistics @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(); crnStatistics = new CrnStatisticsModel(); while (reader.Read()) { var data = new CrnStatisticsModel.Data(); data.InstructorSemAverage = Convert.ToDouble(reader["InstructorSemesterAverage"]); data.InstructorSemSTDev = Convert.ToDouble(reader["InstructorSemesterSTDeviation"].ToString()); data.DepartmentSemAverage = Convert.ToDouble(reader["DepartmentSemesterAverage"]); data.DepartmentSemSTDev = Convert.ToDouble(reader["DepartmentSemesterSTDeviation"]); data.ClassScore = Convert.ToDouble(reader["ClassScore"]); data.ClassSTDev = Convert.ToDouble(reader["ClassSTDeviation"]); data.DecTile = Convert.ToInt32(reader["DecTile"]); data.DepClassFiveYearAverage = Convert.ToDouble(reader["DepartmentClassFiveYearAverage"]); data.DepClassFiveYearSTDev = Convert.ToDouble(reader["DepartmentClassFiveYearSTDeviation"]); data.InstructClassFiveYearAverage = Convert.ToDouble(reader["InstructorClassFiveYearAverage"]); data.InstructClassFiveYearSTDev = Convert.ToDouble(reader["InstructorClassFiveYearSTDeviation"]); crnStatistics.DATA.Add(data); } return(crnStatistics); } catch (SqlException ex) { return(null); } finally { connection.Close(); } }