public async Task ImportProjectService(Guid organizationId, Guid projectId, ProjectServiceImportPostRp resource, string userId = null)
        {
            string loggedUserId = userId ?? _identityService.GetUserId();

            User user = await _userRepository.GetUser(loggedUserId);

            DomainModels.ProjectServiceTemplate projectServiceTemplate = await _projectServiceTemplateRepository.GetProjectServiceTemplateById(resource.ProjectServiceTemplateId);

            if (projectServiceTemplate == null)
            {
                await _domainManagerService.AddConflict($"The pipe template with id {resource.ProjectServiceTemplateId} does not exists.");

                return;
            }

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

                return;
            }

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

                return;
            }

            if (project.Status != EntityStatus.Active)
            {
                await _domainManagerService.AddConflict($"The project with id {projectId} must be in status Active to add a new service.");

                return;
            }

            DomainModels.ProjectService existingService = project.GetServiceByName(resource.Name);
            if (existingService != null)
            {
                await _domainManagerService.AddConflict($"The pipe name {resource.Name} has already been taken.");

                return;
            }

            var gitProviders = organization.GetConfigurationManagementServices(DomainModels.Enums.CMSConnectionType.ProjectLevel);
            var cms          = gitProviders.FirstOrDefault(c => c.OrganizationCMSId.Equals(resource.OrganizationCMSId));

            CMSAuthCredentialModel cmsAuthCredential = this._cmsCredentialService(cms.Type).GetToken(
                _dataProtectorService.Unprotect(cms.AccountId),
                _dataProtectorService.Unprotect(cms.AccountName),
                _dataProtectorService.Unprotect(cms.AccessSecret),
                _dataProtectorService.Unprotect(cms.AccessToken));

            DomainModels.ProjectService newService = user.ImportProjectService(organizationId,
                                                                               projectId, cms.OrganizationCMSId, resource.AgentPoolId, resource.Name, resource.Name, resource.Description,
                                                                               resource.ProjectServiceTemplateId, projectServiceTemplate.PipeType, resource.BranchName, resource.ServiceExternalUrl,
                                                                               resource.ProjectExternalId, resource.ProjectExternalName);

            //SaveChanges in CMS
            CMSServiceCreateModel serviceCreateModel = CMSServiceCreateModel.Factory.Create(project.OrganizationExternalId, project.ProjectExternalId, project.Name, resource.Name, project.ProjectVisibility == ProjectVisibility.Public ? true : false);

            newService.UpdateExternalInformation(resource.ServiceExternalId, resource.ServiceExternalUrl, resource.ServiceExternalName);
            newService.AddEnvironmentsAndVariables(projectServiceTemplate.Parameters);

            _userRepository.Update(user);

            await _userRepository.SaveChanges();

            await _domainManagerService.AddResult("ServiceId", newService.ProjectServiceId);

            var @event = new ProjectServiceImportedEvent(_correlationId)
            {
                BranchName                 = resource.BranchName,
                OrganizationId             = organization.OrganizationId,
                OrganizationName           = organization.Name,
                ProjectId                  = project.ProjectId,
                ServiceId                  = newService.ProjectServiceId,
                ProjectExternalId          = resource.ProjectExternalId,
                ProjectExternalName        = resource.ProjectExternalName,
                ProjectExternalEndpointId  = project.ProjectExternalEndpointId,
                ProjectExternalGitEndpoint = project.ProjectExternalGitEndpoint,
                ProjectVSTSFakeId          = project.ProjectVSTSFakeId,
                ProjectVSTSFakeName        = project.ProjectVSTSFakeName,
                ProjectName                = project.Name,
                AgentPoolId                = newService.AgentPoolId,
                ServiceExternalId          = newService.ProjectServiceExternalId,
                ServiceExternalUrl         = newService.ProjectServiceExternalUrl,
                ServiceName                = resource.Name,
                InternalServiceName        = newService.InternalName,
                ServiceTemplateUrl         = projectServiceTemplate.Url,
                ServiceTemplatePath        = projectServiceTemplate.Path,
                BuildDefinitionYML         = resource.BuildDefinitionYML,

                CMSType            = cms.Type,
                CMSAccountId       = _dataProtectorService.Unprotect(cms.AccountId),
                CMSAccountName     = _dataProtectorService.Unprotect(cms.AccountName),
                CMSAccessId        = _dataProtectorService.Unprotect(cms.AccessId),
                CMSAccessSecret    = _dataProtectorService.Unprotect(cms.AccessSecret),
                CMSAccessToken     = _dataProtectorService.Unprotect(cms.AccessToken),
                UserId             = loggedUserId,
                TemplateParameters = projectServiceTemplate.Parameters.Select(x => new ProjectServiceTemplateParameterCreatedEvent()
                {
                    VariableName = x.VariableName,
                    Value        = x.Value,
                    Scope        = x.Scope
                }).ToList(),
                CPSType                = project.OrganizationCPS.Type,
                CPSAccessId            = _dataProtectorService.Unprotect(project.OrganizationCPS.AccessId),
                CPSAccessName          = _dataProtectorService.Unprotect(project.OrganizationCPS.AccessName),
                CPSAccessSecret        = _dataProtectorService.Unprotect(project.OrganizationCPS.AccessSecret),
                CPSAccessRegion        = _dataProtectorService.Unprotect(project.OrganizationCPS.AccessRegion),
                TemplateAccess         = projectServiceTemplate.TemplateAccess,
                NeedCredentials        = projectServiceTemplate.NeedCredentials,
                RepositoryCMSType      = projectServiceTemplate.TemplateAccess == DomainModels.Enums.TemplateAccess.Organization ? projectServiceTemplate.Credential.CMSType : ConfigurationManagementService.VSTS,
                RepositoryAccessId     = projectServiceTemplate.TemplateAccess == DomainModels.Enums.TemplateAccess.Organization ? projectServiceTemplate.NeedCredentials ? _dataProtectorService.Unprotect(projectServiceTemplate.Credential.AccessId) : string.Empty : string.Empty,
                RepositoryAccessSecret = projectServiceTemplate.TemplateAccess == DomainModels.Enums.TemplateAccess.Organization ? projectServiceTemplate.NeedCredentials ? _dataProtectorService.Unprotect(projectServiceTemplate.Credential.AccessSecret) : string.Empty : string.Empty,
                RepositoryAccessToken  = projectServiceTemplate.TemplateAccess == DomainModels.Enums.TemplateAccess.Organization ? projectServiceTemplate.NeedCredentials ? _dataProtectorService.Unprotect(projectServiceTemplate.Credential.AccessToken) : string.Empty : string.Empty
            };

            //Cloud Provider Data

            await _eventBusService.Publish(queueName : "ProjectServiceImportedEvent", @event : @event);
        }