public async Task <IActionResult> UpdateOrganizationProjectServiceTemplate(Guid organizationId, Guid projectServiceTemplateId, [FromBody] OrganizationProjectServiceTemplatePutRp resourceRp)
        {
            if (!ModelState.IsValid)
            {
                return(this.BadRequest(ModelState));
            }

            await _organizationProjectServiceTemplateService.UpdateOrganizationProjectServiceTemplate(organizationId, projectServiceTemplateId, resourceRp);

            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());
        }
Exemple #2
0
        public async Task UpdateOrganizationProjectServiceTemplate(Guid organizationId, Guid projectServiceTemplateId, OrganizationProjectServiceTemplatePutRp 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;
            }

            PipelineRole role = user.GetRoleInOrganization(organizationId);

            if (role != PipelineRole.OrganizationAdmin)
            {
                await _domainManagerService.AddForbidden($"You are not authorized to create project service templates in this organization.");

                return;
            }

            ProjectServiceTemplate existingTemplate = organization.GetProjectServiceTemplateById(projectServiceTemplateId);

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

                return;
            }

            existingTemplate.Name        = resource.Name;
            existingTemplate.Description = resource.Description;
            existingTemplate.Logo        = resource.Logo;

            _userRepository.Update(user);

            await _userRepository.SaveChanges();
        }