public async Task <IActionResult> ClientRefresh(Guid id) { var model = new CommonResult { IsOk = false }; var integrationClientUid = id; if (integrationClientUid.IsEmptyGuid()) { return(Json(model)); } var request = new IntegrationClientRefreshRequest(CurrentUser.Id, integrationClientUid); var response = await _integrationService.RefreshIntegrationClient(request); if (response.Status.IsNotSuccess) { return(Json(model)); } model.IsOk = true; CurrentUser.IsActionSucceed = true; return(Json(model)); }
public async Task <IntegrationClientRefreshResponse> RefreshIntegrationClient(IntegrationClientRefreshRequest request) { var response = new IntegrationClientRefreshResponse(); 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 integrationClient = await _integrationClientRepository.Select(x => x.Uid == request.IntegrationClientUid); if (integrationClient.IsNotExist()) { response.SetInvalidBecauseNotFound("integration_client"); return(response); } if (integrationClient.OrganizationId != currentUser.OrganizationId) { response.SetInvalid(); return(response); } var integration = await _integrationRepository.SelectById(integrationClient.IntegrationId); if (integration.IsNotExist()) { response.SetInvalidBecauseNotFound("integration"); return(response); } if (!integration.IsActive || !integrationClient.IsActive) { response.SetInvalidBecauseNotActive("integration"); return(response); } _integrationClientFactory.UpdateEntityForRefresh(integrationClient); await _integrationClientRepository.Update(request.CurrentUserId, integrationClient); response.Item = _integrationClientFactory.CreateDtoFromEntity(integrationClient); response.Status = ResponseStatus.Success; return(response); }
public static IntegrationClientRefreshRequest GetIntegrationClientRefreshRequest() { var request = new IntegrationClientRefreshRequest(CurrentUserId, OrganizationOneIntegrationOneIntegrationClientOneUid); return(request); }