public async Task <IActionResult> SubmitExamSubmission(int id, IFormFile examSubmission) { CourseBasicServiceModel course = await this.courseService.GetByIdAsync <CourseBasicServiceModel>(id); if (!examSubmission.FileName.EndsWith(".zip") || examSubmission.Length > ExamSubmissionFileLength) { TempData.AddErrorMessage("Your submission should be a '.zip' file with no more than 2 MB in size."); return(RedirectToAction(nameof(Details), new { id, course.Name })); } byte[] examSubmisionContents = await examSubmission.ToByteArray(); string userId = this.userManager.GetUserId(User); bool submitResult = await this.courseService.SaveExamSubmissionAsync(id, userId, examSubmisionContents); if (!submitResult) { return(BadRequest()); } TempData.AddSuccessMessage("Exam submission uploaded successfully."); return(RedirectToAction(nameof(Details), new { id, name = course.Name })); }
public async Task <IActionResult> SignUp(int id) { CourseBasicServiceModel course = await this.courseService.GetByIdAsync <CourseBasicServiceModel>(id); string userId = this.userManager.GetUserId(User); bool isUserTrainer = await this.trainerService.IsUserTrainerAsync(id, userId); if (isUserTrainer) { TempData.AddErrorMessage("You cannot sign up for course where you are a trainer."); return(RedirectToAction(nameof(Details), new { id, name = course.Name })); } bool signUpResult = await this.courseService.SignUpStudentAsync(userId, id); if (!signUpResult) { return(BadRequest()); } TempData.AddSuccessMessage($"You have successfully signed up for '{course.Name}'."); return(RedirectToAction(nameof(Details), new { id, name = course.Name })); }
public async Task <IActionResult> SignOut(int id) { string userId = this.userManager.GetUserId(User); bool signOutResult = await this.courseService.SignOutStudentAsync(userId, id); if (!signOutResult) { return(BadRequest()); } CourseBasicServiceModel course = await this.courseService.GetByIdAsync <CourseBasicServiceModel>(id); TempData.AddSuccessMessage($"You have successfully signed out from '{course.Name}'."); return(RedirectToAction(nameof(Details), new { id, name = course.Name })); }
public async Task <IActionResult> Course(int id) { string userId = this.userManager.GetUserId(User); bool isUserTrainer = await this.trainerService.IsUserTrainerAsync(id, userId); if (!isUserTrainer) { return(BadRequest()); } IEnumerable <StudentInCourseServiceModel> students = await this.trainerService.GetStudentsInCourseByCourseIdAsync(id); CourseBasicServiceModel course = await this.courseService.GetByIdAsync <CourseBasicServiceModel>(id); CourseWithStudentsViewModel model = new CourseWithStudentsViewModel { Students = students, Course = course }; return(View(model)); }