コード例 #1
0
        public async Task <IActionResult> manage()
        {
            // GetCurrentUserAsync() provides more secure access of current user than passing ID
            var currentuser = await GetCurrentUserAsync();

            // Returning the view model to the view with the courses and users
            ViewCoursesViewModel ViewModel = new ViewCoursesViewModel()
            {
                Courses = _courseService.GetCoursesWithCustomerId(currentuser.CustomerId),
                Users   = _userService.GetUsersWithCustomerId(currentuser.CustomerId)
            };

            return(View(ViewModel));
        }
コード例 #2
0
        public async Task <IActionResult> manage(ViewCoursesViewModel ViewModel) // Posting - used to add new courses
        {
            // GetCurrentUserAsync() provides more secure access of current user than passing ID
            var currentuser = await GetCurrentUserAsync();

            // Returns all courses with customer ID
            var courses = _courseService.GetCoursesWithCustomerId(currentuser.CustomerId);

            // If ModelState isn't valid, this ensures courses are still returned
            ViewModel.Courses = courses;

            // Populates the viewModel to be returned to the view
            if (ViewModel.RegisterCourseViewModel.Name != null && ViewModel.RegisterCourseViewModel.Description != null)
            {
                var model = ViewModel.RegisterCourseViewModel;
                _courseService.AddCourse(model, currentuser.CustomerId);
                var users = _userService.GetUsersWithCustomerId(currentuser.CustomerId);
                courses           = _courseService.GetCoursesWithCustomerId(currentuser.CustomerId);
                ViewModel.Courses = courses;
                ViewModel.Users   = users;
                return(View(ViewModel));
            }
            return(View(ViewModel));
        }