public async Task Execute(UpdateAccountStatusReasonRequest request) { var logObject = new Dictionary <string, object> { { "AccountIdentifer", request.AccountIdentifier }, { "StatusReason", request.ReasonKey }, { "Status", request.Status } }; try { var req = new UpdAccountStatusReasonRequest { AccountIdentifier = request.AccountIdentifier, }; if (!ValidateStatusAndStatusReason(request.ReasonKey, request.Status, req)) { throw new BadRequestException($"Required field Status/ReasonKey is invalid", new LogObject("UpdateAccountStatusReasonManager", logObject)); } await CRMCoreService.UpdAccountStatusReason(req); } catch (GdErrorException) { throw; } catch (Exception ex) { throw new GdErrorException( "Error when executing UpdateAccountStatus", new LogObject("UpdateAccountStatusReasonManager", logObject), ex); } }
private bool ValidateStatusAndStatusReason(string reasonKey, string status, UpdAccountStatusReasonRequest req) { try { if (String.IsNullOrEmpty(reasonKey) && status == null) { return(false); } if (!String.IsNullOrEmpty(reasonKey)) { req.AccountStatusReason = (StateReason)int.Parse(reasonKey); } if (!String.IsNullOrEmpty(status)) { req.Status = status.Trim(); } return(true); } catch (Exception) { return(false); } }
public async Task UpdAccountStatusReason(UpdAccountStatusReasonRequest request) { var logDic = new Dictionary <string, object> { { "AccountIdentifier", request.AccountIdentifier }, { "Status", request.Status }, { "AccountStatusReason", request.AccountStatusReason } }; var endpointUrl = $"{ConfigManager.Instance.GetApiEndpoint("CRMCoreService")}/Account/updateAccountStatus"; try { var rsp = await _apiClient.PostAsync <ResponseBase, UpdAccountStatusReasonRequest> (new Uri(endpointUrl), request, LogOptionEnum.FullLog, logDic); if (rsp == null || rsp.ResponseHeader.StatusCode != HttpStatusCode.OK.ToIntegerString()) { logDic.Add("EndPointUrl", endpointUrl); throw new ExternalErrorException( "Error when calling Reverse route from CRMCoreService. " + rsp.ResponseHeader.SubStatusMessage?.ToString(), new LogObject("CRMCoreService_UpdAccountStatusReason", logDic)); } } catch (ExternalErrorException) { throw; } catch (Exception ex) { logDic.Add("EndPointUrl", endpointUrl); throw new ExternalErrorException( "Error when calling Reverse route from CRMCoreService", new LogObject("CRMCoreService_UpdAccountStatusReason", logDic), ex); } }