public static string ToJsonString(AnswerCountModel model) { if (model == null) { return(null); } else { return(JsonConvert.SerializeObject(model)); } }
public static AnswerCountModel GetAnswerCount(int crn, int semester, int year) { AnswerCountModel answerCount = null; SqlConnection connection = GetConnection(); string selectStatement = "EXEC AnswerCount @crn, @semester, @year"; 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(); answerCount = new AnswerCountModel(); while (reader.Read()) { var data = new AnswerCountModel.Data(); data.crn = Convert.ToInt32(reader["CRN"].ToString()); data.course = reader["Course"].ToString(); data.question = reader["Question"].ToString(); data.answers = reader["Answers"].ToString(); data.answersCount = Convert.ToInt32(reader["Answer Count"].ToString()); data.questionID = Convert.ToInt32(reader["QuestionID"].ToString()); data.sequence = Convert.ToInt32(reader["Sequence"].ToString()); data.studentCount = Convert.ToInt32(reader["Student Count"].ToString()); answerCount.DATA.Add(data); } return(answerCount); } catch (SqlException ex) { return(null); } finally { connection.Close(); } }