Exemplo n.º 1
0
        public async Task <IActionResult> UpdateProjectBasicInformation(Guid organizationId, Guid projectId, [FromBody] ProjectPutRp projectRp)
        {
            if (!ModelState.IsValid)
            {
                return(this.BadRequest(ModelState));
            }

            await _projectService.UpdateProjectBasicInformation(organizationId, projectId, projectRp);

            if (_domainManagerService.HasNotFounds())
            {
                return(this.NotFound(_domainManagerService.GetNotFounds()));
            }

            if (_domainManagerService.HasForbidden())
            {
                return(this.Forbidden(_domainManagerService.GetForbidden()));
            }

            if (_domainManagerService.HasConflicts())
            {
                return(this.Conflict(_domainManagerService.GetConflicts()));
            }

            return(this.Ok());
        }
        public async Task UpdateProjectBasicInformation(Guid organizationId, Guid projectId, ProjectPutRp resource)
        {
            string loggedUserId = _identityService.GetUserId();

            User user = await _userRepository.GetUser(loggedUserId);

            Organization organization = user.FindOrganizationById(organizationId);

            if (organization == null)
            {
                await _domainManagerService.AddNotFound($"The organzation with id {organizationId} does not exists.");

                return;
            }

            Project project = user.FindProjectById(projectId);

            if (project == null)
            {
                await _domainManagerService.AddNotFound($"The project with id {projectId} does not exists.");

                return;
            }

            PipelineRole role = user.GetRoleInProject(projectId);

            if (role != PipelineRole.ProjectAdmin)
            {
                await _domainManagerService.AddForbidden($"You are not authorized to perform updates in this project.");

                return;
            }

            user.UpdateProject(organizationId, projectId, resource.Name, resource.Description);

            _userRepository.Update(user);

            await _userRepository.SaveChanges();
        }