コード例 #1
0
ファイル: WorkFile.cs プロジェクト: zubr404/GalaxyAPI
 private bool NoExistsFile(string fileName, RequestProcessingResult requestResult)
 {
     if (workRepository.Exists(fileName))
     {
         requestResult.FilesNoAdded.Add(new FileNoAdded()
         {
             Name = fileName, ErrorMessage = "Данный файл уже содержится в системе."
         });
         return(false);
     }
     return(true);
 }
コード例 #2
0
        public ActionResult GetImportableProjects(IDEPostData data)
        {
            Course course = _GetCourse();

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

            if (User?.GetName()?.ToLowerInvariant() != data.UserName.ToLowerInvariant())
            {
                return(new HttpStatusCodeResult(HttpStatusCode.Forbidden, "Attempt to retrieve importable projects from another user."));
            }

            try
            {
                var projects = new ImportableProjects();

                var playgrounds = PlaygroundRepository.GetAllPlaygrounds(data.CourseId, data.UserName);
                foreach (var playground in playgrounds)
                {
                    if (typeof(T) == typeof(PlaygroundRepository) && playground.PlaygroundId == data.RepositoryId)
                    {
                        continue;
                    }
                    projects.Playgrounds.Add(new ImportableProjects.ImportableProject()
                    {
                        Type         = ImportableProjects.Types.PLAYGROUND,
                        CourseId     = playground.CourseId,
                        RepositoryId = playground.PlaygroundId,
                        Name         = playground.Name
                    });
                }

                var assignments = _db.StudentAssignments
                                  .Include(sa => sa.Assignment.Course)
                                  .Where(sa => sa.Enrollment.UserName == data.UserName) // CASE INSENSITIVE
                                  .OrderByDescending(sa => sa.Assignment.DateCreated);
                foreach (var assignment in assignments)
                {
                    var name = assignment.Assignment.AssignmentName;
                    if (course.CourseId != assignment.Assignment.CourseId)
                    {
                        name += $" ({assignment.Assignment.Course.ShortName})";
                    }
                    if (typeof(T) != typeof(WorkRepository) || assignment.AssignmentId.Value != data.RepositoryId)
                    {
                        if (WorkRepository.Exists(course.CourseId, data.UserName, data.RepositoryId))
                        {
                            projects.AssignmentWorkspaces.Add(new ImportableProjects.ImportableProject()
                            {
                                Type         = ImportableProjects.Types.WORKSPACE,
                                CourseId     = assignment.Assignment.CourseId,
                                RepositoryId = assignment.AssignmentId.Value,
                                Name         = name
                            });
                        }
                    }
                    if (assignment.HasSubmission)
                    {
                        if (typeof(T) != typeof(SubmissionRepository) || assignment.AssignmentId.Value != data.RepositoryId)
                        {
                            projects.AssignmentSubmissions.Add(new ImportableProjects.ImportableProject()
                            {
                                Type         = ImportableProjects.Types.SUBMISSION,
                                CourseId     = assignment.Assignment.CourseId,
                                RepositoryId = assignment.AssignmentId.Value,
                                Name         = name
                            });
                        }
                    }
                }

                return(new JsonNetResult(projects));
            }
            catch (Exception ex)
            {
                Elmah.ErrorSignal.FromCurrentContext().Raise(ex);
                return(new HttpStatusCodeResult(HttpStatusCode.InternalServerError, ex.Message));
            }
        }