public IActionResult ManageCourse() { var courses = _courseRepository.GetAllCourses(); var CoursesModel = new List <Course>(); foreach (var c in courses) { CoursesModel.Add(new Course { CourseId = c.CourseId, CourseName = c.CourseName, Instructor = c.Instructor }); } var viewModel = new CourseTestViewModel() { Courses = CoursesModel }; foreach (var course in courses) { viewModel.AllCourses.Add(new DropDownListViewModel { Id = course.CourseName, Text = course.CourseName }); } return(View(viewModel)); }
public IActionResult CourseUpdate([FromBody] AddCourseViewModel vm) { var id = _courseRepository.GetCourseIdByTeacherAndCourse(vm.CourseName, vm.InstructorName); var course = _courseRepository.GetCourses(id); var allCourses = _courseRepository.GetAllCourses(); var courses = new List <Course>(); var courseModel = new Course { CourseId = course.CourseId, CourseName = course.CourseName, Instructor = course.Instructor }; foreach (var c in allCourses) { courses.Add(new Course { CourseId = c.CourseId, CourseName = c.CourseName, Instructor = c.Instructor }); } var viewModel = new CourseTestViewModel { Courses = courses, Course = courseModel }; return(PartialView("_SelectedCourse", viewModel)); }
public PartialViewResult Createcourse(CourseTestViewModel model) { if (ModelState.IsValid) { var course = new Course { }; //save _courseRepository.AddCourse(model.Course); _courseRepository.Save(); } else { //error } var courses = _courseRepository.GetAllCourses(); var CoursesModel = new List <Course>(); foreach (var c in courses) { CoursesModel.Add(new Course { CourseId = c.CourseId, CourseName = c.CourseName, Instructor = c.Instructor }); } var viewModel = new CourseTestViewModel() { Courses = CoursesModel }; return(PartialView("_CourseTable", viewModel)); }
public IActionResult CreateCourse() { var courses = _courseRepository.GetAllCourses(); var users = _roleRepository.GetAllUsersByRole("Teacher"); var CoursesModel = new List <Course>(); foreach (var c in courses) { CoursesModel.Add(new Course { CourseId = c.CourseId, CourseName = c.CourseName, Instructor = c.Instructor }); } var viewModel = new CourseTestViewModel() { Courses = CoursesModel }; foreach (var user in users) { viewModel.AllTeachers.Add(new DropDownListViewModel { Id = user.FullName, Text = user.FullName }); } return(View(viewModel)); }
//[ValidateAntiForgeryToken] public IActionResult CourseEdit(CourseTestViewModel viewModel) { var model = new Course { CourseName = viewModel.Course.CourseName, Instructor = viewModel.Course.Instructor }; //save _courseRepository.Edit(model); _courseRepository.Save(); return(RedirectToAction("CreateCourse")); }
public IActionResult ViewCourse() { var allCourses = _courseRepository.GetAllCourses(); var courses = new List <Course>(); foreach (var c in allCourses) { courses.Add(new Course { CourseId = c.CourseId, CourseName = c.CourseName, Instructor = c.Instructor }); } var viewModel = new CourseTestViewModel { Courses = courses }; return(View(viewModel)); }
public PartialViewResult ViewCourse(CourseTestViewModel viewModel) { return(PartialView("_CourseTable", viewModel)); }