Exemplo n.º 1
0
        public async Task <IActionResult> Delete(
            [HttpTrigger(AuthorizationLevel.Function, "delete", Route = "data/projectTypes/{projectTypeId}")] HttpRequest httpRequest, string projectTypeId)
        {
            if (httpRequest is null)
            {
                throw new ArgumentNullException(nameof(httpRequest));
            }

            if (projectTypeId is null)
            {
                throw new ArgumentNullException(nameof(projectTypeId));
            }

            var projectType = await projectTypesRepository
                              .GetAsync(projectTypeId)
                              .ConfigureAwait(false);

            if (projectType is null)
            {
                return(new NotFoundResult());
            }

            await projectTypesRepository
            .RemoveAsync(projectType)
            .ConfigureAwait(false);

            return(new OkObjectResult(projectType));
        }
Exemplo n.º 2
0
        public async Task <List <ProjectTypeDto> > GetAllOfProjectTypes()
        {
            using (var scope = _dbContextScopeFactory.CreateReadOnly())
            {
                var projectTypes = await _projectTypeRepository.GetAsync(e => e.IsActive == true);

                return(_mapper.Map <List <ProjectTypeDto> >(projectTypes));
            }
        }
        public async Task <IActionResult> Get(string projectTypeId)
        {
            var projectType = await projectTypesRepository
                              .GetAsync(projectTypeId)
                              .ConfigureAwait(false);

            if (projectType is null)
            {
                return(ErrorResult
                       .NotFound($"A ProjectType with the ID '{projectTypeId}' could not be found in this TeamCloud Instance")
                       .ToActionResult());
            }

            var returnProjectType = projectType.PopulateExternalModel();

            return(DataResult <ProjectType>
                   .Ok(returnProjectType)
                   .ToActionResult());
        }
Exemplo n.º 4
0
        public async Task <IActionResult> Post([FromBody] ProjectDefinition projectDefinition)
        {
            if (projectDefinition is null)
            {
                throw new ArgumentNullException(nameof(projectDefinition));
            }

            var validation = new ProjectDefinitionValidator().Validate(projectDefinition);

            if (!validation.IsValid)
            {
                return(ErrorResult
                       .BadRequest(validation)
                       .ToActionResult());
            }

            var nameExists = await ProjectRepository
                             .NameExistsAsync(projectDefinition.Name)
                             .ConfigureAwait(false);

            if (nameExists)
            {
                return(ErrorResult
                       .Conflict($"A Project with name '{projectDefinition.Name}' already exists. Project names must be unique. Please try your request again with a unique name.")
                       .ToActionResult());
            }

            var projectId = Guid.NewGuid().ToString();

            var users = await ResolveUsersAsync(projectDefinition, projectId)
                        .ConfigureAwait(false);

            var project = new ProjectDocument
            {
                Id         = projectId,
                Users      = users,
                Name       = projectDefinition.Name,
                Tags       = projectDefinition.Tags,
                Properties = projectDefinition.Properties
            };

            if (!string.IsNullOrEmpty(projectDefinition.ProjectType))
            {
                project.Type = await projectTypeRepository
                               .GetAsync(projectDefinition.ProjectType)
                               .ConfigureAwait(false);

                if (project.Type is null)
                {
                    return(ErrorResult
                           .BadRequest(new ValidationError {
                        Field = "projectType", Message = $"A Project Type with the ID '{projectDefinition.ProjectType}' could not be found in this TeamCloud Instance. Please try your request again with a valid Project Type ID for 'projectType'."
                    })
                           .ToActionResult());
                }
            }
            else
            {
                project.Type = await projectTypeRepository
                               .GetDefaultAsync()
                               .ConfigureAwait(false);

                if (project.Type is null)
                {
                    return(ErrorResult
                           .BadRequest(new ValidationError {
                        Field = "projectType", Message = $"No value was provided for 'projectType' and there is no a default Project Type set for this TeamCloud Instance. Please try your request again with a valid Project Type ID for 'projectType'."
                    })
                           .ToActionResult());
                }
            }

            var currentUser = users.FirstOrDefault(u => u.Id == UserService.CurrentUserId);

            var command = new OrchestratorProjectCreateCommand(currentUser, project);

            return(await Orchestrator
                   .InvokeAndReturnActionResultAsync <ProjectDocument, Project>(command, Request)
                   .ConfigureAwait(false));
        }