Exemplo n.º 1
0
        public IHttpActionResult GetProject(int projectId)
        {
            Require.Positive(projectId, nameof(projectId));

            var issueTypes = new[] { IssueType.Research, IssueType.Task }.ToList();
            var statusOfIssues = new[] { IssueStatus.Ready, IssueStatus.InProgress }.ToList();

            try
            {
                var project = _projectProvider.GetProject(projectId, issueTypes, statusOfIssues);

                if (User.IsInRole(AccountRole.User))
                {
                    return(Ok(_projectsMapper.ToAdminProject(project)));
                }

                if (!ProjectsPolicies.OnlyPublic(project) || !ProjectsPolicies.OnlyDoneOrInProgress(project))
                {
                    return(Unauthorized());
                }

                return(Ok(_projectsMapper.ToProject(project)));
            }
            catch (ProjectNotFoundException)
            {
                return(NotFound());
            }
        }
Exemplo n.º 2
0
        public IEnumerable <IndexPageProject> GetRandomIndexPageProjects(int count)
        {
            Require.ZeroOrGreater(count, nameof(count));

            List <Project> requiredProjects;

            if (User.IsInRole(AccountRole.User))
            {
                requiredProjects = _projectProvider.GetProjects();
            }
            else
            {
                requiredProjects = _projectProvider.GetProjects(
                    project => ProjectsPolicies.OnlyDoneOrInProgress(project) &&
                    ProjectsPolicies.OnlyPublic(project));
            }

            var randomProjects = requiredProjects.GetRandom(count);

            return(randomProjects.Select(_projectsMapper.ToIndexPageProject));
        }