Example #1
0
        public async Task <IActionResult> DownloadExam(int id, string studentId)
        {
            if (string.IsNullOrEmpty(studentId))
            {
                return(BadRequest());
            }

            var userId = _userManager.GetUserId(this.User);

            if (!await _trainerService.IsTrainer(id, userId))
            {
                return(BadRequest());
            }

            var studentInCourseNames = await _trainerService.StudentInCourseNamesAsync(id, studentId);

            if (studentInCourseNames == null)
            {
                return(BadRequest());
            }

            var examContents = await _trainerService.GetExamSubmission(id, studentId);

            if (examContents == null)
            {
                return(BadRequest("No exam submitted."));
            }

            return(File(examContents, "application/zip", $"{studentInCourseNames.CourseName}-{studentInCourseNames.UserName}-{DateTime.UtcNow.ToString(DateTimeFormat)}.zip"));
        }