public static string ToJsonString(YearsTaughtModel model) { if (model == null) { return(null); } else { return(JsonConvert.SerializeObject(model)); } }
public static YearsTaughtModel GetYearsTaught(int instructorID) { YearsTaughtModel yearsTaught = null; SqlConnection connection = GetConnection(); string selectStatement = "EXEC YearsTaught @instructorID"; SqlCommand command = new SqlCommand(selectStatement, connection); command.Parameters.AddWithValue("instructorID", instructorID); try { connection.Open(); SqlDataReader reader = command.ExecuteReader(); yearsTaught = new YearsTaughtModel(); while (reader.Read()) { var data = new YearsTaughtModel.Data(); data.instructorid = Convert.ToInt32(reader["instructorID"].ToString()); data.semester = Convert.ToInt32(reader["semester"].ToString()); data.year = Convert.ToInt32(reader["Year"].ToString()); yearsTaught.DATA.Add(data); } return(yearsTaught); } catch (SqlException ex) { return(null); } finally { connection.Close(); } }