public async Task <IActionResult> Edit(int?id) { if (id == null) { return(NotFound()); } var instructor = _instructorRepository.GetById((int)id); var allCourses = _courseRepository.GetAll(); var coursesToInstructor = await _courseAssignmentRepository .CoursesToInstructorAsync(instructor.InstructorId); var model = new EditCreateViewModel() { Instructor = instructor, AssignedCourseData = allCourses.Select(s => new AssignedCourseData() { CourseId = s.Id, CourseName = s.CourseName, Assigned = coursesToInstructor.Exists(e => e.Course.Id == s.Id) }).ToList() }; return(View(model)); }
public void AssignInstructorToCourse(int instructorId, int courseId) { var instructor = _instructorRepository.GetById(instructorId); var course = _courseRepository.GetById(courseId); instructor.Courses.Add(course); SaveCourseInstructor(); }
public IActionResult OnGet(int id) { Instructor = _instructorRepository.GetById(id); if (Instructor == null) { return(NotFound()); } return(Page()); }
public void AssignInstructorToCourseOffering(int instructorId, int courseOfferingId) { var courseOffering = _courseOfferingRepository.GetById(courseOfferingId); var instructor = _instructorRepository.GetById(instructorId); instructor.CourseOfferings.Add(courseOffering); _instructorRepository.Update(instructor); SaveCourseOffering(); }
public async Task <IActionResult> Edit(int id) { var instructor = _instructorRepository.GetById(id); var allCourses = _courseRepository.GetAll(); var coursesToInstructor = await _courseAssignmentRepository.CoursesToInstructorAsync(instructor.InstructorId); var model = new CreateInstructorViewModel() { Instructor = instructor, AssignedCourseData = allCourses.Select(s => new AssignedCourseData() { CourseId = s.CourseId, CourseName = s.CourseName, Assigned = coursesToInstructor.Exists(x => x.Course.CourseId == s.CourseId) }).OrderBy(x => x.CourseName).ToList() }; return(View(model)); }
public IActionResult Edit(long id) { try { var output = _instructorRepository.GetById(id); if (output != null) { return(Ok(output)); } else { return(NotFound(_NotFound)); } } catch (Exception e) { return(BadRequest(e)); } }
public async Task <StudentsGradeByInstructor> ListGradesGiven(int instructorId) { var instructor = await _instructorRepository.GetById(instructorId); if (instructor == null) { throw new ArgumentException($"There's no instructor with the instructorId = {instructorId}"); } var enrollments = await _enrollmentRepository.GetByInstructorId(instructorId); if (!enrollments.Any()) { throw new Exception($"The instructor with the Id = {instructorId} never gave a grade"); } var result = new StudentsGradeByInstructor { Instructor = $"{instructor.FirstName} {instructor.LastName}", InstructorId = instructorId }; foreach (var enrollment in enrollments) { result.GradeXStudentXCourse.Add( new StudentsGradeInfo { Grade = enrollment.Grade, StudentId = enrollment.StudentId, Student = $"{enrollment.Student.FirstName} {enrollment.Student.LastName}", CourseId = enrollment.CourseId, Course = enrollment.Course.Title } ); } return(result); }
public Instructor GetInstructorById(int Id) { return(instructorRepository.GetById(Id)); }
public Instructor GetInstructorById(string id) { return(_instructorRepository.GetById(id)); }
public Instructor GetInstructorById(int id) { return(_repository.GetById(id)); }
public Instructor GetById(Guid id) { return(instructorRepository.GetById(id)); }
public Instructor GetInstructor(int instructorId) { return(_instructorRepository.GetById(instructorId)); }