/// <summary> /// Gets bp ID and acct status while validating acct ID and fullName. /// </summary> /// <param name="lookupCustomerRequest">The lookup customer request.</param> /// <returns></returns> public async Task <LookupCustomerModel> LookupCustomer(LookupCustomerRequest lookupCustomerRequest) { LookupCustomerModel lookupCustomerModel = new LookupCustomerModel(); // Validate acct ID with bp ID lookup BPByContractAccountEntity bpByContractAccountEntity = await _bpByContractAccountRepository.GetBpByContractAccountId(lookupCustomerRequest.ContractAccountNumber); if (bpByContractAccountEntity != null) { // Update return value lookupCustomerModel.BPId = bpByContractAccountEntity.BusinessPartner_Id; // Get customer for this bp CustomerEntity customerEntity = await _customerRepository.GetCustomerByBusinessPartnerId(bpByContractAccountEntity.BusinessPartner_Id); if (customerEntity != null) { try { // Validate name against Customer table- all uppercase if (lookupCustomerRequest.NameOnBill.ToUpper() != customerEntity.FullName) { // Pass null model to indicate not found lookupCustomerModel = null; } else { // Check for web account in auth var accountExistsResponse = await _authenticationApi.GetAccountExists(customerEntity.BusinessPartnerId); if (accountExistsResponse?.Data?.Exists != null) { // Update return value lookupCustomerModel.HasWebAccount = accountExistsResponse.Data.Exists; } } } catch (Exception e) { _logger.LogError("GetAccountExists API call failed for " + $"{nameof(customerEntity.BusinessPartnerId)}: {customerEntity.BusinessPartnerId}\n" + $"{e.Message}"); throw; } } else { // Pass null model to indicate not found lookupCustomerModel = null; } } else { // Pass null model to indicate not found lookupCustomerModel = null; } return(lookupCustomerModel); }
public async Task LookupCustomer_Test() { //Arrange const long bpId = 123456789; const long acctId = 123456789012; const bool hasWebAccount = true; const string testFullName = "JON SMITH"; var lookupCustomerRequest = new LookupCustomerRequest { ContractAccountNumber = acctId, NameOnBill = testFullName, }; CustomerLogicMock.Setup(clm => clm.LookupCustomer(It.IsAny <LookupCustomerRequest>())) .Returns((LookupCustomerRequest request) => { var lookupCustomerModel = new LookupCustomerModel { BPId = bpId, HasWebAccount = hasWebAccount, }; return(Task.FromResult(lookupCustomerModel)); }); var target = GetController(); //Act var actual = await target.LookupCustomer(lookupCustomerRequest); //Assert actual.ShouldNotBeNull(); actual.ShouldBeOfType <OkObjectResult>(); var response = ((OkObjectResult)actual).Value as LookupCustomerResponse; response.ShouldNotBeNull(); response.BPId.ShouldBe(bpId.ToString()); response.HasWebAccount.ShouldBe(hasWebAccount); }
public async Task <IActionResult> LookupCustomer(LookupCustomerRequest lookupCustomerRequest) { IActionResult result; _logger.LogInformation($"LookupCustomer({nameof(lookupCustomerRequest)}: {lookupCustomerRequest.ToJson()})"); try { LookupCustomerModel lookupCustomerModel = await _customerLogic.LookupCustomer(lookupCustomerRequest); // If the cassandra call fails w/o raising an error it means that the contractAccountId wasn't found if (lookupCustomerModel != null) { var response = new LookupCustomerResponse() { BPId = lookupCustomerModel.BPId.ToString(), HasWebAccount = lookupCustomerModel.HasWebAccount, }; _logger.LogInformation("LookupCustomer: " + response.ToJson()); result = Ok(response); } else { // This is on purpose to avoid raising a 404 error. Per Peter. result = StatusCode(204); } } catch (Exception ex) { _logger.LogError("Unable to lookup customer", ex.Message); result = ex.ToActionResult(); } return(result); }