コード例 #1
0
        public async Task <IActionResult> Download(string sectionName)
        {
            var section = Classroom.Sections
                          .SingleOrDefault(s => s.Name == sectionName);

            if (section == null)
            {
                return(NotFound());
            }

            var archiveContents = await SubmissionService.DownloadSubmissionsAsync
                                  (
                ClassroomName,
                ProjectName,
                CheckpointName,
                sectionName
                                  );

            var timestamp = TimeZoneProvider.ToUserLocalTime(DateTime.UtcNow)
                            .ToString("yyyyMMdd-HHmmss");

            var filename = $"{Classroom.Name}-{Project.Name}-{Checkpoint.Name}-{timestamp}.zip";

            return(File(archiveContents, "application/zip", filename));
        }
コード例 #2
0
        /// <summary>
        /// Once the user has chosen the download properties, made the student selections, and clicked
        /// the main form submit button, this initiates the actual download
        /// </summary>
        /// <param name="downloadSubmissionViewModel">ViewModel for the form</param>
        public async Task <IActionResult> DownloadSubmissionsAsync(DownloadSubmissionViewModel downloadSubmissionViewModel)
        {
            var selectedStudents = downloadSubmissionViewModel.SectionsAndStudents
                                   .Where
                                   (
                sas => sas.SectionName.Selected
                                   )
                                   .SelectMany
                                   (
                sas => sas.SelectedStudents
                .Where
                (
                    ss => ss.Selected &&
                    (ss.Submitted || downloadSubmissionViewModel.IncludeUnsubmitted)
                )
                .Select
                (
                    ss => ss.Id
                )
                                   ).ToList();

            if (selectedStudents.Count == 0)
            {
                return(NotFound());
            }

            var archiveContents = await SubmissionService.DownloadSubmissionsAsync
                                  (
                ClassroomName,
                ProjectName,
                CheckpointName,
                selectedStudents,
                downloadSubmissionViewModel.Format
                                  );

            var timestamp = TimeZoneProvider.ToUserLocalTime(DateTime.UtcNow)
                            .ToString("yyyyMMdd-HHmmss");

            var filename = $"{Classroom.Name}-{Project.Name}-{Checkpoint.Name}-{timestamp}.zip";

            return(File(archiveContents, "application/zip", filename));
        }