Beispiel #1
0
        public bool SubmitAssignment(int assignmentId, byte[] zipData, string authToken)
        {
            if (!_authService.IsValidKey(authToken))
            {
                return(false);
            }
            try
            {
                Assignment  assignment = _db.Assignments.Find(assignmentId);
                UserProfile user       = _authService.GetActiveUser(authToken);
                CourseUser  courseUser = _db.CourseUsers
                                         .Where(cu => cu.AbstractCourseID == assignment.CourseID)
                                         .Where(cu => cu.UserProfileID == user.ID)
                                         .FirstOrDefault();
                Team team = (from tm in _db.TeamMembers
                             join at in _db.AssignmentTeams on tm.TeamID equals at.TeamID
                             where tm.CourseUserID == courseUser.ID &&
                             at.AssignmentID == assignmentId
                             select tm.Team).FirstOrDefault();

                OSBLE.Models.FileSystem.AssignmentFilePath fs =
                    Models.FileSystem.Directories.GetAssignment(
                        (int)assignment.CourseID, assignmentId);

                MemoryStream ms = new MemoryStream(zipData);
                ms.Position = 0;
                using (ZipFile file = ZipFile.Read(ms))
                {
                    foreach (ZipEntry entry in file.Entries)
                    {
                        MemoryStream extractStream = new MemoryStream();
                        entry.Extract(extractStream);
                        extractStream.Position = 0;

                        //delete existing
                        fs.Submission(team.ID)
                        .File(entry.FileName)
                        .Delete();

                        //add the extracted file to the file system
                        bool result = fs.Submission(team.ID)
                                      .AddFile(entry.FileName, extractStream);
                        if (result == false)
                        {
                            return(false);
                        }
                    }
                }
            }
            catch (Exception)
            {
                return(false);
            }
            return(true);
        }
Beispiel #2
0
        public byte[] GetAssignmentSubmission(int assignmentId, string authToken)
        {
            if (!_authService.IsValidKey(authToken))
            {
                return(new byte[0]);
            }
            UserProfile profile    = _authService.GetActiveUser(authToken);
            Assignment  assignment = _db.Assignments.Find(assignmentId);

            //make sure that the user is enrolled in the course
            CourseUser courseUser = (from cu in _db.CourseUsers
                                     where cu.AbstractCourseID == assignment.CourseID
                                     &&
                                     cu.UserProfileID == profile.ID
                                     select cu).FirstOrDefault();

            if (courseUser == null)
            {
                return(new byte[0]);
            }

            //users are attached to assignments through teams, so we have to find the correct team
            Team team = (from tm in _db.TeamMembers
                         join at in _db.AssignmentTeams on tm.TeamID equals at.TeamID
                         where tm.CourseUserID == courseUser.ID &&
                         at.AssignmentID == assignmentId
                         select tm.Team).FirstOrDefault();

            if (team == null)
            {
                return(new byte[0]);
            }


            OSBLE.Models.FileSystem.AssignmentFilePath fs =
                Models.FileSystem.Directories.GetAssignment(
                    courseUser.AbstractCourseID, assignmentId);
            Stream stream = fs.Submission(team.ID)
                            .AllFiles()
                            .ToZipStream();
            MemoryStream ms = new MemoryStream();

            try
            {
                stream.CopyTo(ms);
            }
            catch (Exception)
            {
            }
            byte[] bytes = ms.ToArray();
            stream.Close();
            ms.Close();
            return(bytes);
        }
Beispiel #3
0
        public ActionResult SaveABET()
        {
            // Get the file storage for this assignment's submissions
            OSBLE.Models.FileSystem.AssignmentFilePath afs =
                OSBLE.Models.FileSystem.Directories.GetAssignment(
                    Convert.ToInt32(Request.Form["hdnCourseID"]),
                    Convert.ToInt32(Request.Form["hdnAssignmentID"]));

            foreach (string key in Request.Form.AllKeys)
            {
                if (key.StartsWith("slctProficiency"))
                {
                    // The key will end with the team ID
                    int teamID;
                    if (!int.TryParse(key.Substring(key.IndexOf('y') + 1), out teamID))
                    {
                        continue;
                    }

                    // Get the submission for the team
                    OSBLE.Models.FileSystem.OSBLEDirectory attrFP =
                        afs.Submission(teamID) as OSBLE.Models.FileSystem.OSBLEDirectory;
                    OSBLEFile file = attrFP.FirstFile;
                    if (null == file)
                    {
                        continue;
                    }

                    // Update the attribute for the submission and save
                    file.ABETProficiencyLevel = Request.Form[key];
                    file.SaveAttrs();
                }
            }

            // Send the user back to the assignments index page
            return(RedirectToRoute(new { action = "Index", controller = "Assignment", area = "" }));
        }
Beispiel #4
0
        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));
            }
        }