public async Task <CourseNameWithStudentNameServiceModel> GetCourseNameAndStudentName(int courseId, string studentId) { string courseName = await this.database .Courses .Where(c => c.Id == courseId) .Select(c => c.Name) .FirstOrDefaultAsync(); if (courseName == null) { return(null); } string studentName = await this.database .Users .Where(u => u.Id == studentId) .Select(u => u.Name) .FirstOrDefaultAsync(); if (studentName == null) { return(null); } CourseNameWithStudentNameServiceModel model = new CourseNameWithStudentNameServiceModel { CourseName = courseName, StudentName = studentName }; return(model); }
public async Task <IActionResult> DownloadExamSubmission(int id, string studentId) { if (string.IsNullOrEmpty(studentId)) { return(BadRequest()); } string userId = this.userManager.GetUserId(User); bool isUserTrainer = await this.trainerService.IsUserTrainerAsync(id, userId); if (!isUserTrainer) { return(BadRequest()); } byte[] examSubmissionContents = await this.trainerService.DownloadExamSubmission(id, studentId); if (examSubmissionContents == null) { this.TempData.AddErrorMessage("This student did not upload exam submission yet."); return(RedirectToAction(nameof(Course), new { id })); } CourseNameWithStudentNameServiceModel model = await this.trainerService.GetCourseNameAndStudentName(id, studentId); if (model == null) { return(BadRequest()); } return(File(examSubmissionContents, "application/zip", $"{model.CourseName} - {model.StudentName} - {DateTime.UtcNow.ToString("DD-MM-YYYY")}.zip")); }