public Course AddCourse(RegisterCourseViewModel model, int customerId) { Course course = new Course() { CustomerId = customerId, Description = model.Description, Name = model.Name, TimeStamp = DateTime.Now, }; _courseRepository.Add(course); Scene scene = new Scene() { CourseId = course.Id }; _sceneService.AddScene(scene); VRBackground background = new VRBackground() { SceneId = scene.Id }; _backgroundService.AddImage(background); return(course); }
public ActionResult Register(RegisterCourseViewModel model) { if (ModelState.IsValid) { try { Student student = (Student)context.Users.Find(User.Identity.GetUserId()); foreach (int courseId in model.SelectedCourses) { StudentCourse sc = new StudentCourse { CourseId = courseId, StudentId = student.Id, Year = DateTime.Now.Year.ToString(), Semester = DateTime.Now.Month < 7 ? 1 : 2 }; context.StudentCourses.Add(sc); } context.SaveChanges(); TempData["SuccessMessage"] = "You have been enrolled in the courses."; } catch (Exception ex) { TempData["ErrorMessage"] = ex.Message; } } return(RedirectToAction("StudentDashboard", "Home", null)); }
public IActionResult RegisterCourse() { RegisterCourseViewModel model = new RegisterCourseViewModel(); GetAllCourseYears(model); GetAllDepartments(model); return(Redirect("allcourses")); }
public void TestAddCourse_EmptyRegisterCourseViewModel_Null() { RegisterCourseViewModel m = new RegisterCourseViewModel() { }; Course c = _courseService.AddCourse(m, 5); // Tests that the newly added RegisterCourseViewModel name is correctly returned after adding Assert.Null(c.Name); }
private RegisterCourseViewModel GetAllCourseYears(RegisterCourseViewModel model) { var courseYears = courseYearRepo.GetAll(); foreach (var year in courseYears) { model.CourseYears.Add(new SelectListItem { Text = year.YearTitle, Value = year.Id.ToString() }); } return(model); }
private RegisterCourseViewModel GetAllDepartments(RegisterCourseViewModel model) { var departments = departmentRepo.GetAll(); foreach (var department in departments) { model.Departments.Add(new SelectListItem { Text = department.DepartmentName, Value = department.Id.ToString() }); } return(model); }
public void TestAddCourse_Success() { RegisterCourseViewModel m = new RegisterCourseViewModel() { Name = "New Course Name", Description = "New Course Description" }; Course c = _courseService.AddCourse(m, 5); // Tests that the newly added RegisterCourseViewModel name is correctly returned after adding Assert.Equal("New Course Name", c.Name); }
public async Task AddCourse(string CourseName, string CourseDescription) // adds course from the Dashboard page with jQuery { // Gets the current user var currentuser = await GetCurrentUserAsync(); // Creates the RegisterCourseViewModel to pass to the service layer RegisterCourseViewModel m = new RegisterCourseViewModel() { Description = CourseDescription, Name = CourseName, CustomerId = currentuser.CustomerId }; _courseService.AddCourse(m, currentuser.CustomerId); }
public IActionResult RegisterCourse(RegisterCourseViewModel model) { if (ModelState.IsValid) { Course course = new Course { CourseCode = model.CourseCode, CourseName = model.CourseName, CourseYearId = model.CourseYearId, DepartmentId = model.DepartmentId }; entityRepository.Insert(course); entityRepository.Save(); return(Redirect("allcourses")); } return(View(model)); }
public ActionResult Register() { // The logged in student Student student = (Student)context.Users.Find(User.Identity.GetUserId()); string year = DateTime.Now.Year.ToString(); int semester = DateTime.Now.Month < 7 ? 1 : 2; IEnumerable <StudentCourse> studentCourses = context.StudentCourses.Where(c => c.StudentId == student.Id).ToList(); if (studentCourses.Any(c => c.StudentId == student.Id && c.Year == year && c.Semester == semester)) { TempData["InfoMessage"] = "You have already registered courses for this semester."; return(RedirectToAction("StudentDashboard", "Home", null)); } else { IEnumerable <Course> courses = context.Curriculum.Where(c => c.Year == student.Year).Where(c => c.Semester == semester).Where(c => c.Program.ProgramId == student.ProgramId).Where(c => c.LevelId == student.LevelId).ToList(); RegisterCourseViewModel model = new RegisterCourseViewModel(); model.Courses = courses; return(View(model)); } }