Example #1
0
        public ActionResult GetSubmissionDetails(SubmissionPostData data)
        {
            Course course = _GetCourse();

            if (course == null || course.CourseId != data.CourseId)
            {
                return(new HttpNotFoundResult());
            }

            var user = ApplicationUser.Current;

            if (user == null || user.Id != data.UserId)
            {
                return(new HttpNotFoundResult());
            }

            try
            {
                var submission = _db.StudentSubmissions
                                 .Where(ss => ss.StudentAssignment.Enrollment.CourseId == data.CourseId)
                                 .Where(ss => ss.StudentAssignment.Enrollment.UserId == user.Id)
                                 .Where(ss => ss.StudentAssignment.AssignmentId == data.AssignmentId)
                                 .Where(ss => ss.StudentSubmissionId == data.SubmissionId)
                                 .Include(ss => ss.StudentAssignment.Assignment)
                                 .Include(ss => ss.StudentAssignment.Enrollment)
                                 .FirstOrDefault();

                if (submission == null)
                {
                    return(new HttpNotFoundResult());
                }

                var repo = SubmissionRepository.Get(submission.StudentAssignment);
                repo.Checkout(submission.CommitId); // get selected
                var dir = TempDir.Get(repo);

                var folder = dir.GetFolder();

                return(new JsonNetResult(new { Folder = folder, Results = submission.PreSubmissionResults }));
            }
            catch (Exception ex)
            {
                Elmah.ErrorSignal.FromCurrentContext().Raise(ex);
                return(new HttpStatusCodeResult(HttpStatusCode.InternalServerError, ex.Message));
            }
        }
Example #2
0
        public ActionResult ImportProject(ProjectImportPostData data)
        {
            var repo = _GetRepo(data);

            if (repo == null)
            {
                return(new HttpNotFoundResult());
            }

            Repository sourceRepo = null;
            int        courseId   = data.SourceCourseId > 0 ? data.SourceCourseId : data.CourseId;

            if (data.SourceType == ImportableProjects.Types.PLAYGROUND)
            {
                string userName = String.IsNullOrWhiteSpace(data.SourceUserName) ? data.UserName : data.SourceUserName;
                sourceRepo = PlaygroundRepository.Get(courseId, userName, data.SourceRepositoryId);
            }
            else if (data.SourceType == ImportableProjects.Types.WORKSPACE)
            {
                sourceRepo = WorkRepository.Get(courseId, data.UserName, data.SourceRepositoryId);
            }
            else if (data.SourceType == ImportableProjects.Types.SUBMISSION)
            {
                sourceRepo = SubmissionRepository.Get(courseId, data.UserName, data.SourceRepositoryId);
                sourceRepo.Checkout();
            }
            if (sourceRepo == null)
            {
                return(new HttpNotFoundResult());
            }

            try
            {
                repo.Commit("Before Import Project");
                repo.CopyFromRepository(sourceRepo);
                repo.Commit("After Import Project");
                return(Json("success"));
            }
            catch (Exception ex)
            {
                Elmah.ErrorSignal.FromCurrentContext().Raise(ex);
                return(new HttpStatusCodeResult(HttpStatusCode.InternalServerError, ex.Message));
            }
        }