예제 #1
0
        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));
        }
예제 #2
0
        public void AssignInstructorToCourse(int instructorId, int courseId)
        {
            var instructor = _instructorRepository.GetById(instructorId);
            var course     = _courseRepository.GetById(courseId);

            instructor.Courses.Add(course);
            SaveCourseInstructor();
        }
예제 #3
0
 public IActionResult OnGet(int id)
 {
     Instructor = _instructorRepository.GetById(id);
     if (Instructor == null)
     {
         return(NotFound());
     }
     return(Page());
 }
예제 #4
0
        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();
        }
예제 #5
0
        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));
        }
예제 #6
0
 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));
     }
 }
예제 #7
0
        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);
        }
예제 #8
0
 public Instructor GetInstructorById(int Id)
 {
     return(instructorRepository.GetById(Id));
 }
예제 #9
0
 public Instructor GetInstructorById(string id)
 {
     return(_instructorRepository.GetById(id));
 }
예제 #10
0
 public Instructor GetInstructorById(int id)
 {
     return(_repository.GetById(id));
 }
예제 #11
0
 public Instructor GetById(Guid id)
 {
     return(instructorRepository.GetById(id));
 }
예제 #12
0
 public Instructor GetInstructor(int instructorId)
 {
     return(_instructorRepository.GetById(instructorId));
 }