public ActionResult Create([Bind(Include = "StudentId,FirstName,SecondName")] Student student) { if (ModelState.IsValid) { db.students.Add(student); db.SaveChanges(); return(RedirectToAction("Index")); } return(View(student)); }
public ActionResult Create([Bind(Include = "LecturerID,LecturerName")] Lecturer lecturer) { if (ModelState.IsValid) { db.Lecturers.Add(lecturer); db.SaveChanges(); return(RedirectToAction("Index")); } return(View(lecturer)); }
public ActionResult Create([Bind(Include = "SubjectId,SubjectName")] Subject subject) { if (ModelState.IsValid) { db.subjects.Add(subject); db.SaveChanges(); return(RedirectToAction("Index")); } return(View(subject)); }
public ActionResult Create([Bind(Include = "StudentID,StudentFName,StudentLName")] Student student) { if (ModelState.IsValid) { db.Students.Add(student); db.SaveChanges(); return(RedirectToAction("Index")); } ViewBag.StudentID = new SelectList(db.StudentSubjects, "StudentID", "StudentID", student.StudentID); return(View(student)); }
public ActionResult Create([Bind(Include = "AttendanceId,AttendanceDate,SubjectId,StudentId,Present")] Attendance attendance) { if (ModelState.IsValid) { db.Attendances.Add(attendance); db.SaveChanges(); return(RedirectToAction("Index")); } ViewBag.StudentId = new SelectList(db.Students, "StudentId", "FirstName", attendance.StudentId); ViewBag.SubjectId = new SelectList(db.Subjects, "SubjectId", "SubjectName", attendance.SubjectId); return(View(attendance)); }
//when to put context.saveChanges()? //seed students private void SeedStudents(AttendDBContext context) { context.Students.AddOrUpdate( p => p.StudentId, new Student { StudentId = "S01", FirstName = "Josh", LastName = "Knock" }, new Student { StudentId = "S02", FirstName = "Marry", LastName = "Lee" } ); context.SaveChanges(); }
//seed student subjects private void SeedStudentSubjects(AttendDBContext context) { context.StudentSubjects.AddOrUpdate( new StudentSubject { StudentId = "S01", SubjectId = 1 }, new StudentSubject { StudentId = "S01", SubjectId = 2 }, new StudentSubject { StudentId = "S02", SubjectId = 3 }, new StudentSubject { StudentId = "S02", SubjectId = 8 } ); context.SaveChanges(); }
//seed attendance private void SeedAttendaces(AttendDBContext context) { context.Attendances.AddOrUpdate( new Attendance { AttendanceId = 1, AttendanceDate = DateTime.Now, SubjectId = 1, StudentId = "S01", Present = true }, new Attendance { AttendanceId = 2, AttendanceDate = DateTime.Now, SubjectId = 2, StudentId = "S01", Present = false }, new Attendance { AttendanceId = 3, AttendanceDate = DateTime.Now, SubjectId = 3, StudentId = "S02", Present = true }, new Attendance { AttendanceId = 4, AttendanceDate = DateTime.Now, SubjectId = 8, StudentId = "S02", Present = true } ); context.SaveChanges(); }
private void SeedSubjects(AttendDBContext context) { context.Subjects.AddOrUpdate( s => s.SubjectId, new Subject { SubjectName = "RAD" }, new Subject { SubjectName = "Web" }, new Subject { SubjectName = "Database" }, new Subject { SubjectName = "Soft Prj Mgm" } ); context.SaveChanges(); }
//seed lectures and each lecture teaching one subject each private void SeedLectures(AttendDBContext context) { context.Lectures.AddOrUpdate( new Lecture { LectureId = 1, LectureName = "John K" }, new Lecture { LectureId = 2, LectureName = "Kathy B" } ); context.LectureSubjects.AddOrUpdate( new LectureSubject { LectureId = 1, SubjectId = 1 }, new LectureSubject { LectureId = 2, SubjectId = 8 } ); context.SaveChanges(); }