public async Task <List <StaffObj> > GetAllStaffAsync() { try { var gosGatewayClient = _httpClientFactory.CreateClient("GOSDEFAULTGATEWAY"); var response = new StaffRespObj { Status = new APIResponseStatus { IsSuccessful = true, Message = new APIResponseMessage() } }; var result = await gosGatewayClient.GetAsync(ApiRoutes.IdentitySeverWorkflow.GET_ALL_STAFF); var resultString = await result.Content.ReadAsStringAsync(); response = JsonConvert.DeserializeObject <StaffRespObj>(resultString); if (!result.IsSuccessStatusCode) { response.Status.IsSuccessful = false; response.Status.Message.FriendlyMessage = $"{result.ReasonPhrase} {(int)result.StatusCode} {result.Content}"; throw new Exception($"{response}"); } if (!response.Status.IsSuccessful) { return(new List <StaffObj>()); } return(response.staff); } catch (Exception ex) { #region Log error var errorCode = ErrorID.Generate(4); _logger.Error($"ErrorID : {errorCode} Ex : {ex?.Message ?? ex?.InnerException?.Message} ErrorStack : {ex?.StackTrace}"); return(new List <StaffObj>()); #endregion } }
public async Task <StaffRespObj> GetAllStaffAsync() { return(await _retryPolicy.ExecuteAsync(async() => { try { var gosGatewayClient = _httpClientFactory.CreateClient("GOSDEFAULTGATEWAY"); string authorization = _accessor.HttpContext.Request.Headers["Authorization"]; gosGatewayClient.DefaultRequestHeaders.Add("Authorization", authorization); StaffRespObj responseObj = new StaffRespObj(); try { result = await gosGatewayClient.GetAsync(ApiRoutes.Workflow.GET_ALL_STAFF); if (!result.IsSuccessStatusCode) { new StaffRespObj { Status = new APIResponseStatus { Message = new APIResponseMessage { FriendlyMessage = result.ReasonPhrase } } }; } var data = await result.Content.ReadAsStringAsync(); responseObj = JsonConvert.DeserializeObject <StaffRespObj>(data); } catch (Exception ex) { throw ex; } if (responseObj == null) { return new StaffRespObj { Status = new APIResponseStatus { IsSuccessful = false, Message = new APIResponseMessage { FriendlyMessage = "System Error!! Please contact Administrator" } } }; } if (!responseObj.Status.IsSuccessful) { return new StaffRespObj { Status = new APIResponseStatus { IsSuccessful = responseObj.Status.IsSuccessful, Message = responseObj.Status.Message } }; } return new StaffRespObj { staff = responseObj.staff, Status = new APIResponseStatus { IsSuccessful = responseObj.Status.IsSuccessful, Message = responseObj.Status.Message } }; } catch (Exception ex) { throw ex; } })); }