public ActionResult GetAllCritReviews(int assignmentId) { Assignment assignment = db.Assignments.Find(assignmentId); Stream submission = null; if (assignment.Type == AssignmentTypes.CriticalReview) { //Critical Review: We want all the reviews this team was set to do. ZipFile zipfile = new ZipFile(); //List of all the teams who the current team was set to review List <ReviewTeam> reviewTeams = (from rt in db.ReviewTeams where rt.AssignmentID == assignmentId select rt).ToList(); //Add each review into the zip Dictionary <string, dynamic> reviewStreams = new Dictionary <string, dynamic>(); foreach (ReviewTeam reviewTeam in reviewTeams) { string key = reviewTeam.AuthorTeam.Name; OSBLE.Models.FileSystem.FileCollection fc = Models.FileSystem.Directories.GetAssignment( ActiveCourseUser.AbstractCourseID, assignmentId) .Review(reviewTeam.AuthorTeam, reviewTeam.ReviewingTeam) .AllFiles(); //don't create a zip if we don't have have anything to zip. if (fc.Count > 0) { var bytes = fc.ToBytes(); reviewStreams[key] = bytes; } } Random rnd = new Random(); foreach (string author in reviewStreams.Keys) { foreach (string file in reviewStreams[author].Keys) { string location = string.Format("{0}/{1}", "Review of Anoymous " + rnd.Next(), file); zipfile.AddEntry(location, reviewStreams[author][file]); } } submission = new MemoryStream(); zipfile.Save(submission); submission.Position = 0; } string ZipName = assignment.AssignmentName + ".zip"; return(new FileStreamResult(submission, "application/octet-stream") { FileDownloadName = ZipName }); }
public ActionResult GetDocumentsForCriticalReview(int assignmentId, int authorTeamId) { Assignment CRAssignment = db.Assignments.Find(assignmentId); AssignmentTeam CurrentUsersTeam = GetAssignmentTeam(CRAssignment, ActiveCourseUser); Team authorTeam = db.Teams.Find(authorTeamId); //Getting a list of all the Team Ids for the current user to review. List <int> AllTeamsToReview = (from rt in CRAssignment.ReviewTeams where rt.ReviewTeamID == CurrentUsersTeam.TeamID select rt.AuthorTeamID).ToList(); //If authorTeamId is not in the list of author teams being reviewed by current user, then permission is denied. if (AllTeamsToReview.Contains(authorTeamId)) { //Send off to Annotate if we have exactly one deliverable and that deliverable is a PDF document if (CRAssignment.PreceedingAssignment.Deliverables.Count == 1 && CRAssignment.PreceedingAssignment.Deliverables[0].DeliverableType == DeliverableType.PDF) { return(RedirectToRoute(new { controller = "PdfCriticalReview", action = "Review", assignmentID = assignmentId, authorTeamID = authorTeamId })); } //Document not handled by Annotate, must collect author teams preceding assignment's submission OSBLE.Models.FileSystem.FileCollection AuthorTeamSubmission = Models.FileSystem.Directories.GetAssignment( ActiveCourseUser.AbstractCourseID, CRAssignment.PrecededingAssignmentID.Value) .Submission(authorTeamId) .AllFiles(); //Checking if author should be anonymized. string displayName = authorTeam.Name; if (AnonymizeAuthor(CRAssignment, authorTeam)) { displayName = "Anonymous " + authorTeamId; } string zipFileName = string.Format("{0}'s submission for {1}.zip", displayName, CRAssignment.PreceedingAssignment.AssignmentName); return(new FileStreamResult(AuthorTeamSubmission.ToZipStream(), "application/octet-stream") { FileDownloadName = zipFileName }); } return(RedirectToAction("Index", "Home")); }
public ActionResult GetSubmissionZip(int assignmentId, int teamId, bool resubmission = false) { //basic assignments have the option of being annotatable. In this case, //send off to annotate rather than creating a zip file. Assignment assignment = db.Assignments.Find(assignmentId); Team team = db.Teams.Find(teamId); if (assignment.Type == AssignmentTypes.Basic && assignment.IsAnnotatable == true) { if (assignment.HasDeliverables && assignment.Deliverables[0].DeliverableType == DeliverableType.PDF) { if (resubmission) { return(RedirectToRoute(new { controller = "PdfCriticalReviewHTTPS", action = "Grade", assignmentID = assignmentId, authorTeamID = teamId, resubmission = resubmission })); } else { return(RedirectToRoute(new { controller = "PdfCriticalReview", action = "Grade", assignmentID = assignmentId, authorTeamID = teamId, resubmission = resubmission })); } } } Stream submission = null; if (assignment.Type == AssignmentTypes.CriticalReview) { //Critical Review: We want all the reviews this team was set to do. ZipFile zipfile = new ZipFile(); //List of all the teams who the current team was set to review List <ReviewTeam> reviewTeams = (from rt in db.ReviewTeams where rt.AssignmentID == assignmentId && rt.ReviewTeamID == teamId select rt).ToList(); //Add each review into the zip Dictionary <string, dynamic> reviewStreams = new Dictionary <string, dynamic>(); foreach (ReviewTeam reviewTeam in reviewTeams) { string key = reviewTeam.AuthorTeam.Name; OSBLE.Models.FileSystem.FileCollection fc = Models.FileSystem.Directories.GetAssignment( ActiveCourseUser.AbstractCourseID, assignmentId) .Review(reviewTeam.AuthorTeam, reviewTeam.ReviewingTeam) .AllFiles(); //don't create a zip if we don't have have anything to zip. if (fc.Count > 0) { var bytes = fc.ToBytes(); reviewStreams[key] = bytes; } } foreach (string author in reviewStreams.Keys) { foreach (string file in reviewStreams[author].Keys) { string location = string.Format("{0}/{1}", "Review of " + author, file); zipfile.AddEntry(location, reviewStreams[author][file]); } } submission = new MemoryStream(); zipfile.Save(submission); submission.Position = 0; } else //Basic Assigment, only need to get submissions { submission = OSBLE.Models.FileSystem.Directories.GetAssignmentSubmission( ActiveCourseUser.AbstractCourseID, assignmentId, teamId) .AllFiles() .ToZipStream(); } string ZipName = assignment.AssignmentName + " by " + team.Name + ".zip"; return(new FileStreamResult(submission, "application/octet-stream") { FileDownloadName = ZipName }); }
public ActionResult Index(int assignmentId) { if (ActiveCourseUser == null) //user is not logged in { return(RedirectToRoute(new { controller = "Home", action = "Index", area = "" })); } ViewBag.HideMail = ActiveCourseUser != null?DBHelper.GetAbstractCourseHideMailValue(ActiveCourseUser.AbstractCourseID) : false; Assignment assignment = db.Assignments.Find(assignmentId); //If the assignment does not exist, or the assignment has not been released and the user is a student: kick them out if (assignment == null || (assignment.ReleaseDate > DateTime.UtcNow && ActiveCourseUser.AbstractRoleID == (int)OSBLE.Models.Courses.CourseRole.CourseRoles.Student)) { return(RedirectToRoute(new { action = "Index", controller = "Assignment", area = "" })); } AssignmentDetailsFactory factory = new AssignmentDetailsFactory(); AssignmentDetailsViewModel viewModel = factory.Bake(assignment, ActiveCourseUser); // E.O.: There can be files associated with an assignment description and solutions. We look // for these now. ViewBag.DescFilesHTML = string.Empty; ViewBag.SoluFilesHTML = string.Empty; if (assignment.CourseID.HasValue) { OSBLE.Models.FileSystem.AssignmentFilePath fs = OSBLE.Models.FileSystem.Directories.GetAssignment( assignment.CourseID.Value, assignmentId); OSBLEDirectory attrFiles = fs.AttributableFiles; OSBLE.Models.FileSystem.FileCollection files = attrFiles.GetFilesWithSystemAttribute("assignment_description", assignmentId.ToString()); if (files.Count > 0) { StringBuilder sb = new StringBuilder("<ul>"); foreach (string fileName in files) { //Check to see if the user is an admin if (CurrentUser.CanCreateCourses == true) { //Build the URL action for deleting //Assignment file deletion is handled different. string UrlAction = Url.Action("DeleteAssignmentFile", "Home", new { courseID = assignment.CourseID.Value, assignmentID = assignment.ID, fileName = System.IO.Path.GetFileName(fileName) }); // Make a link for the file sb.AppendFormat( "<li><a href=\"/Services/CourseFilesOps.ashx?cmd=assignment_file_download" + "&courseID={0}&assignmentID={1}&filename={2}\">{2} </a>" + "<a href=\"" + UrlAction + "\"><img src=\"/Content/images/delete_up.png\" alt=\"Delete Button\"></img></a>" + "</li>", assignment.CourseID.Value, assignment.ID, System.IO.Path.GetFileName(fileName)); } else { sb.AppendFormat( "<li><a href=\"/Services/CourseFilesOps.ashx?cmd=assignment_file_download" + "&courseID={0}&assignmentID={1}&filename={2}\">{2}</li>", assignment.CourseID.Value, assignment.ID, System.IO.Path.GetFileName(fileName)); } } sb.Append("</ul>"); ViewBag.DescFilesHTML = sb.ToString(); } //Check for solution files and if they exist create a string to send to the assignment details attrFiles = fs.AttributableFiles; files = attrFiles.GetFilesWithSystemAttribute("assignment_solution", assignmentId.ToString()); //Check active course user ///////////////////////// // This is checking hard coded AbstractCourseID values, // needs to check if the User is enrolled in the current course ID // this will cause errors in the future, noted for now ////////////////////////// //if (files.Count > 0 && (ActiveCourseUser.AbstractCourseID == 1 ||ActiveCourseUser.AbstractCourseID == 2 || // ActiveCourseUser.AbstractCourseID == 3 || ActiveCourseUser.AbstractCourseID == 5)) if (currentCourses.Contains(ActiveCourseUser)) { bool pastCourseDueDate = DBHelper.AssignmentDueDatePast(assignmentId, ActiveCourseUser.AbstractCourseID); DateTime?CourseTimeAfterDueDate = DBHelper.AssignmentDueDateWithLateHoursInCourseTime(assignmentId, ActiveCourseUser.AbstractCourseID); StringBuilder sb; // make sure we don't have an incorrect assignmentId if (CourseTimeAfterDueDate != null) { sb = new StringBuilder("<ul>"); foreach (string fileName in files) { //Check to see if the user can modify the course if (ActiveCourseUser.AbstractRole.CanModify) { //Build the URL action for deleting //Assignment file deletion is handled different. string UrlAction = Url.Action("DeleteAssignmentFile", "Home", new { courseID = assignment.CourseID.Value, assignmentID = assignment.ID, fileName = System.IO.Path.GetFileName(fileName) }); string fName = System.IO.Path.GetFileName(fileName); // Make a link for the file sb.AppendFormat( "<li><a href=\"/Services/CourseFilesOps.ashx?cmd=assignment_file_download" + "&courseID={0}&assignmentID={1}&filename={2}\">{3} </a>" + "<a href=\"" + UrlAction + "\"><img src=\"/Content/images/delete_up.png\" alt=\"Delete Button\"></img></a>" + "</li>", assignment.CourseID.Value, assignment.ID, fName, fName + " (Viewable after " + CourseTimeAfterDueDate + ")"); } else if (!pastCourseDueDate) { sb.AppendFormat( "<li>Viewable after {0}", CourseTimeAfterDueDate); } // past due date, give link to the file else { sb.AppendFormat( "<li><a href=\"/Services/CourseFilesOps.ashx?cmd=assignment_file_download" + "&courseID={0}&assignmentID={1}&filename={2}\">{2}</li>", assignment.CourseID.Value, assignment.ID, System.IO.Path.GetFileName(fileName)); } } sb.Append("</ul>"); ViewBag.SoluFilesHTML = sb.ToString(); } } } //discussion assignments and critical reviews require their own special view if (assignment.Type == AssignmentTypes.TeamEvaluation) { return(View("TeamEvaluationIndex", viewModel)); } else if (assignment.Type == AssignmentTypes.DiscussionAssignment || assignment.Type == AssignmentTypes.CriticalReviewDiscussion) { return(View("DiscussionAssignmentIndex", viewModel)); } //MG&MK: For teamevaluation assignments, assignment details uses the //previous assingment teams for displaying. So, we are forcing //TeamEvaluation assignment to use TeamIndex. else if (assignment.HasTeams || assignment.Type == AssignmentTypes.TeamEvaluation) { return(View("TeamIndex", viewModel)); } else { return(View("Index", viewModel)); } }