public async Task <IActionResult> Post([FromBody] ClientApiDto client) { var clientDto = client.ToClientApiModel <ClientDto>(); await _clientService.AddClientAsync(clientDto); return(Ok()); }
public async Task <bool> UpdateAppClient(ClientApiDto clientApiDto, AppClientDto appClientDto) { if (clientApiDto is null) { return(false); } if (appClientDto is null) { return(false); } if (appClientDto.Id == string.Empty) { return(false); } if (appClientDto.Revision == string.Empty) { return(false); } var res = await apiLao.UpdateClient(clientApiDto); if (res) { var result = await couchContext.EditAsync <AppClientDto>(couchDbHelper, appClientDto); return(result.IsSuccess); } return(false); //var result = await couchContext.EditAsync<AppClientDto>(couchDbHelper, appClientDto); //return result.IsSuccess; }
public async Task <bool> CreateAppClient(AppClient appClient) { if (appClient.ClientId == string.Empty) { return(false); } if (appClient.UserID == string.Empty) { return(false); } var req = new ClientApiDto() { ClientId = appClient.ClientId, ClientName = appClient.ClientName, Description = appClient.Description }; var res = await apiLao.CreateClient(req); if (res) { appClient.AppID = req.Id; var result = await couchContext.InsertAsync <AppClient>(couchDbHelper, appClient); return(result.IsSuccess); } return(false); }
public async Task <bool> CreateClient(ClientApiDto clientApi) { // discover endpoints from metadata var client = new HttpClient(); var disco = await client.GetDiscoveryDocumentAsync(IdentityEndpoint.Discovery); if (disco.IsError) { return(false); } // request token var req = new PasswordTokenRequest { Address = disco.TokenEndpoint, ClientId = IdentityEndpoint.ClientID, ClientSecret = IdentityEndpoint.Secret, Scope = IdentityEndpoint.Scopes, UserName = IdentityEndpoint.UserName, Password = IdentityEndpoint.Password }; var tokenResponse = await client.RequestPasswordTokenAsync(req); if (tokenResponse.IsError) { return(false); } var apiClient = new HttpClient(); apiClient.SetBearerToken(tokenResponse.AccessToken); var dataJson = JsonSerializer.Serialize(clientApi); var stringContent = new StringContent(dataJson, Encoding.UTF8, "application/json"); var response = await apiClient.PostAsync(IdentityEndpoint.ClientUri, stringContent); if (response.IsSuccessStatusCode) { var resDeserialize = await JsonHelper.Deserialize <ClientApiDto>(response, defaultOptions); clientApi.Id = resDeserialize.Id; } return(response.IsSuccessStatusCode); }
public async Task <IActionResult> Post([FromBody] ClientApiDto client) { var clientDto = client.ToClientApiModel <ClientDto>(); if (!clientDto.Id.Equals(default))