public static CrnDetailsModel GetCrnDetails(int crn, int semester, int year) { CrnDetailsModel crnDetails = null; SqlConnection connection = GetConnection(); string selectStatement = "EXEC CrnDetails @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(); crnDetails = new CrnDetailsModel(); while (reader.Read()) { var data = new CrnDetailsModel.Data(); data.classString = reader["ClassString"].ToString(); data.crn = Convert.ToInt32(reader["bannerCRN"].ToString()); data.section = reader["Section"].ToString(); data.semester = Convert.ToInt32(reader["Semester"].ToString()); data.semesterString = reader["SemesterString"].ToString(); /*if (!reader["Block"].ToString().Equals("NULL")) * data.block = Convert.ToInt32(reader["Block"].ToString()); */ data.block = 0; data.year = Convert.ToInt32(reader["Year"].ToString()); data.subjectCode = reader["SubjectCode"].ToString(); data.courseNum = Convert.ToInt32(reader["CourseNumber"].ToString()); data.instructorID = Convert.ToInt32(reader["instructorID"].ToString()); data.firstName = reader["FirstName"].ToString(); data.lastName = reader["LastName"].ToString(); data.email = reader["Email"].ToString(); data.responses = Convert.ToInt32(reader["responses"].ToString()); data.students = Convert.ToInt32(reader["students"].ToString()); data.testID = Convert.ToInt32(reader["testID"].ToString()); data.testName = reader["testName"].ToString(); crnDetails.DATA.Add(data); } return(crnDetails); } catch (SqlException ex) { return(null); } finally { connection.Close(); } }
public static string ToJsonString(CrnDetailsModel model) { if (model != null) { return(JsonConvert.SerializeObject(model)); } else { return(null); } }