public ActionResult Solutions(int id, bool compete, SubmissionExportType exportType) { var userHasAccessToContest = this.User.IsAdmin() || this.Data.Contests .All() .Any(c => c.Id == id && (c.Lecturers.Any(cl => cl.LecturerId == this.UserProfile.Id) || c.Category.Lecturers.Any(cl => cl.LecturerId == this.UserProfile.Id))); if (!userHasAccessToContest) { this.TempData.AddDangerMessage("Нямате привилегиите за това действие"); return(this.RedirectToAction("Index", "Contests")); } var contestName = this.Data.Contests.All().Where(x => x.Id == id).Select(c => c.Name).FirstOrDefault(); if (string.IsNullOrWhiteSpace(contestName)) { this.TempData[GlobalConstants.DangerMessage] = "Няма такова състезание"; return(this.RedirectToAction("Index", "Home", new { area = string.Empty })); } var problems = this.GetContestProblems(id); var participants = this.GetContestParticipants(id, compete); var fileComment = PrepareSolutionsFileComment(compete, contestName, participants.Count, problems); var file = PrepareSolutionsZipFile(fileComment); Func <int, int, Submission> getSubmissionFunc = null; switch (exportType) { case SubmissionExportType.BestSubmissions: getSubmissionFunc = this.GetBestSubmission; break; case SubmissionExportType.LastSubmissions: getSubmissionFunc = this.GetLastSubmission; break; } this.ZipParticipantsSolutions(participants, file, problems, getSubmissionFunc); // Send file to the user var zipFileName = string.Format( "{1} {2} submissions for {0}.zip", contestName, compete ? "Contest" : "Practice", exportType == SubmissionExportType.BestSubmissions ? "best" : exportType == SubmissionExportType.LastSubmissions ? "last" : "all"); return(new ZipFileResult(file, zipFileName)); }
public ActionResult Solutions(int id, bool compete, SubmissionExportType exportType) { var userHasAccessToContest = this.User.IsAdmin() || this.contestsData.IsUserLecturerInByContestAndUser(id, this.UserProfile.Id); if (!userHasAccessToContest) { return(this.RedirectToContestsAdminPanelWithNoPrivilegesMessage()); } var contestName = this.contestsData.GetNameById(id); if (string.IsNullOrWhiteSpace(contestName)) { this.TempData[GlobalConstants.DangerMessage] = "Няма такова състезание"; return(this.RedirectToAction("Index", "Home", new { area = string.Empty })); } var problems = this.GetContestProblems(id); var participants = this.GetContestParticipants(id, compete); var fileComment = PrepareSolutionsFileComment(compete, contestName, participants.Count, problems); var file = PrepareSolutionsZipFile(fileComment); Func <int, int, Submission> getSubmissionFunc = null; switch (exportType) { case SubmissionExportType.BestSubmissions: getSubmissionFunc = this.GetBestSubmission; break; case SubmissionExportType.LastSubmissions: getSubmissionFunc = this.GetLastSubmission; break; } this.ZipParticipantsSolutions(participants, file, problems, getSubmissionFunc); // Send file to the user var zipFileName = string.Format( "{1} {2} submissions for {0}.zip", contestName, compete ? "Contest" : "Practice", exportType == SubmissionExportType.BestSubmissions ? "best" : exportType == SubmissionExportType.LastSubmissions ? "last" : "all"); return(new ZipFileResult(file, zipFileName)); }