예제 #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);
        }
예제 #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);
        }
예제 #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 = "" }));
        }