// // GET: /Course/Create public ActionResult Create() { var subjects = _repo.Subjects.All; var faculties = _repo.Faculties.All; var course = new Course(); var vm = new CourseInputModel(course, subjects, faculties); return View(vm); }
public ActionResult Create(Course course) { try { // TODO: Add insert logic here if (ModelState.IsValid) { _repo.Courses.Add(course); _repo.SaveChanges(); } return RedirectToAction("Index"); } catch { return View(); } }
public ActionResult Edit(int id, Course course) { try { if (ModelState.IsValid) { var item = _repo.Courses.All.FirstOrDefault(c => c.Id == id); item.Name = course.Name; item.Code = course.Code; item.Start = course.Start; item.Credit = course.Credit; item.FacultyId = course.FacultyId; item.SubjectId = course.SubjectId; _repo.SaveChanges(); return RedirectToAction("Index"); } var subjects = _repo.Subjects.All; var faculties = _repo.Faculties.All; var vm = new CourseInputModel(course, subjects, faculties); return View(vm); } catch { return View(); } }
public CourseInputModel(Course course, IEnumerable subjects, IEnumerable faculties) { Course = course; Subjects = new SelectList(subjects, "Id", "Name", course.SubjectId); Faculties = new SelectList(faculties, "Id", "Name", course.FacultyId); }