public ViewResult addCourseForm(Course courseAdded) { CourseRepository repository = new CourseRepository(); repository.AddCourse(courseAdded.CourseName, courseAdded.CourseId, courseAdded.Syllabus, courseAdded.AnnouncementId); return View("courseAdded", courseAdded); }
public Course GetBy(int id) { Course course; var sql = string.Format("SELECT * FROM Course WHERE courseId = '{0}'", id); var connectionString = "Server=(local);Database=Savnac.Database;Trusted_Connection=True;"; var command = new SqlCommand(sql, new SqlConnection(connectionString)); using (var connection = command.Connection) { connection.Open(); using (var reader = command.ExecuteReader(CommandBehavior.CloseConnection)) { reader.Read(); course = new Course() { CourseId = id, CourseName = reader["courseName"].ToString(), Syllabus = reader["syllabusName"].ToString() //AnnouncementId = (int)reader["announcementId"] }; } connection.Close(); } if (course.AnnouncementId != -1) { sql = string.Format("SELECT * FROM Announcement WHERE announcementId = '{0}'", course.AnnouncementId); command = new SqlCommand(sql, new SqlConnection(connectionString)); using (var connection = command.Connection) { connection.Open(); using (var reader = command.ExecuteReader(CommandBehavior.CloseConnection)) { reader.Read(); course.Announcement = new AnnouncementModel() { user = reader["username"].ToString(), title = reader["title"].ToString(), body = reader["body"].ToString(), timePosted = (DateTime)reader["timePosted"], classId = id }; } connection.Close(); } } else { course.Announcement = new AnnouncementModel(); } return course; }