public async Task <List <AccountSearchInfo> > Execute(AccountSearchRequest request) { var logObject = new Dictionary <string, object> { { "Search Option", request.Option.Value } }; try { var response = new List <AccountSearchInfo>(); var coreSearchResults = new List <CustomerInfo>(); switch (request.Option) { case SearchOptionEnum.AccountNumber: coreSearchResults = await CRMCoreService.GetCustomerInfoByAccountNumber(request.Value); break; case SearchOptionEnum.SSN: coreSearchResults = await CRMCoreService.GetCustomerInfoBySSN(request.Value); break; case SearchOptionEnum.CustomerInfo: var coreRequest = new SearchAccountByDetailRequest(); if (!ProcessCustomerDetailsRequest(ref coreRequest, request.Value)) { throw new GdErrorException("Error while executing AccountSearch by customer detailes", new LogObject("AccountSearchManager_AccountSearch", new Dictionary <string, object> { { "Option", request.Option.ToString() }, { "Value", "" } })); } coreSearchResults = await CRMCoreService.GetCustomerInfoByCustomerDetail(coreRequest); break; } if (coreSearchResults == null || !coreSearchResults.Any()) { throw new NotFoundException("No record found", new LogObject("AccountSearch", logObject)); } MappingResponse(response, coreSearchResults); return(response); } catch (GdErrorException) { throw; } catch (Exception ex) { throw new GdErrorException( "Error when executing AccountSearch", new LogObject("AccountSearchManager", logObject), ex); } }
private static bool ProcessCustomerDetailsRequest(ref SearchAccountByDetailRequest request, string value) { if (string.IsNullOrWhiteSpace(value)) { return(false); } try { var conditionsSort = JsonConvert.DeserializeObject <SortedList <string, string> >(value) .Where(pair => pair.Value.Trim() != "").ToDictionary(pair => pair.Key, pair => pair.Value); if (conditionsSort.Count >= 2) { foreach (var condition in conditionsSort) { typeof(SearchAccountByDetailRequest).GetProperty(condition.Key).SetValue( request, condition.Key != "DOB" ? (object)condition.Value : DateTime.ParseExact(condition.Value, "MMddyyyy", System.Globalization.CultureInfo.InvariantCulture, System.Globalization.DateTimeStyles.None).ToString("yyyy-MM-dd")); } return(!string.IsNullOrEmpty(request.LastName)); } return(false); } catch (Exception) { return(false); } }
public async Task <List <CustomerInfo> > GetCustomerInfoByCustomerDetail(SearchAccountByDetailRequest request) { var logDic = new Dictionary <string, object> { { "ZipCode", request.ZipCode }, { "DOB", "" }, { "FirstName", "" }, { "LastName", "" }, }; var endpointUrl = $"{ConfigManager.Instance.GetApiEndpoint("CRMCoreService")}/Account/getCustomerInfoByDetails"; try { var handler = new HttpClientHandler { UseDefaultCredentials = true, PreAuthenticate = true }; _apiClient.Client = new HttpClient(handler); var response = await _apiClient.PostAsync <SearchAccountResponse, SearchAccountByDetailRequest>(new Uri(endpointUrl), request, LogOptionEnum.FullLog, logDic); return(HandleNoSuccessResponse <SearchAccountResponse>(response, logDic, MethodBase.GetCurrentMethod().Name) ? null : response.CustomerInfo); } catch (Exception ex) { logDic.Add("EndPointUrl", endpointUrl); throw new ExternalErrorException( "Error when calling getCustomerInfoByDetails route from CRMcoreService", new LogObject("CRMCoreService_GetCustomerInfoByCustomerDetail", logDic), ex); throw; } }