Exemple #1
0
        // GET: Instructors
        public async Task <IActionResult> Index(int?id, int?courseId, [FromServices] IInstructorService service)
        {
            var viewModel = new InstructorListDto();

            try
            {
                viewModel.Instructors = await service.ListAllInstructorsAsync();

                if (id.HasValue)
                {
                    ViewData["InstructorId"] = id.Value;
                    viewModel.Courses        = await service.ListAllInstructorCoursesAsync(id.Value);
                }

                if (courseId.HasValue)
                {
                    ViewData["CourseId"]  = courseId.Value;
                    viewModel.Enrollments = await service.ListAllStudentsEnrolledInCourseAsync(courseId.Value);
                }
            }
            catch (Exception ex)
            {
                _logger.LogError(ex, "Exception in Index: " + ex.Message);
                ViewBag.HasError = true;
                ViewBag.Message  = Constants.ERROR_MESSAGE_STANDARD + ": " + ex.Message;
            }

            return(View($"{_viewFolder}Index.cshtml", viewModel));
        }