public async Task <IActionResult> ClientCreate(Guid id)
        {
            var integrationUid = id;

            if (integrationUid.IsEmptyGuid())
            {
                return(Json(new CommonResult {
                    IsOk = false
                }));
            }

            var request  = new IntegrationClientCreateRequest(CurrentUser.Id, integrationUid);
            var response = await _integrationService.CreateIntegrationClient(request);

            if (response.Status.IsNotSuccess)
            {
                return(Json(new CommonResult {
                    IsOk = false, Messages = response.ErrorMessages
                }));
            }

            var integrationClientRow = GetIntegrationClientRow(response.Item);

            CurrentUser.IsActionSucceed = true;
            return(Json(new CommonResult {
                IsOk = true, Item = integrationClientRow
            }));
        }
Esempio n. 2
0
        public async Task <IntegrationClientCreateResponse> CreateIntegrationClient(IntegrationClientCreateRequest request)
        {
            var response = new IntegrationClientCreateResponse();

            var currentUser = _cacheManager.GetCachedCurrentUser(request.CurrentUserId);

            if (!currentUser.IsAdmin)
            {
                response.SetInvalid();
                return(response);
            }

            if (await _organizationRepository.Any(x => x.Id == currentUser.OrganizationId && !x.IsActive))
            {
                response.SetInvalidBecauseNotActive("organization");
                return(response);
            }

            var integration = await _integrationRepository.Select(x => x.Uid == request.IntegrationUid);

            if (integration.IsNotExist())
            {
                response.SetInvalidBecauseNotFound("integration");
                return(response);
            }

            if (integration.OrganizationId != currentUser.OrganizationId)
            {
                response.SetInvalid();
                return(response);
            }

            var entity = _integrationClientFactory.CreateEntity(integration);
            await _integrationClientRepository.Insert(request.CurrentUserId, entity);

            response.Item   = _integrationClientFactory.CreateDtoFromEntity(entity);
            response.Status = ResponseStatus.Success;
            return(response);
        }
        public static IntegrationClientCreateRequest GetIntegrationClientCreateRequest()
        {
            var request = new IntegrationClientCreateRequest(CurrentUserId, UidOne);

            return(request);
        }