/// <summary> /// Get Bp relationship based on a given BP /// </summary> /// <param name="bpId"></param> /// /// <param name="jwt"></param> /// <returns></returns> public async Task <BpRelationshipsResponse> GetBprelationships(BpRelationshipRequestParam bprelationRequestParam) { _logger.LogInformation($"GetBprelationshipsr: GetBprelationships({nameof(bprelationRequestParam.LoggedInBp)} : {bprelationRequestParam.LoggedInBp})"); try { BpRelationshipsMcfResponse resp; if (!string.IsNullOrEmpty(bprelationRequestParam.TenantBp)) { resp = await _mcfClient.GetBprelationships(bprelationRequestParam.TenantBp); } else { resp = await _mcfClient.GetBprelationships(bprelationRequestParam.LoggedInBp, bprelationRequestParam.Jwt); } var bprelations = MapBpRelations(resp); return(bprelations); } catch (Exception ex) { _logger.LogError(ex, $"Failed to GetBprelationships for {bprelationRequestParam.LoggedInBp}"); throw ex; } }
public async Task <IActionResult> GetAllBpRelationships([FromQuery] string tenantBpId) { IActionResult result; try { //get the Bp from the JWT var bpId = GetBpIdFromClaims(); var jwt = GetJWToken(); var bpRelationParam = new BpRelationshipRequestParam() { LoggedInBp = bpId.ToString(), Jwt = jwt, TenantBp = tenantBpId }; var resp = await _moveInLogic.GetBprelationships(bpRelationParam); var bpRelation = MapToBpRelation(resp); result = Ok(bpRelation); } catch (Exception ex) { _logger.LogError(ex, "Unable to get all bp relationsships BP for a customer", ex.Message); result = ex.ToActionResult(); } return(result); }
/// <summary> /// Creates Autorized contact /// Get Customer Relationships Get /v{version}/customer/bp-relationships ///Check to see if customer is existing(and active) contact customer /// If yes and active – no action required /// If yes and not currently valid – Update valid to date to 1231999? /// If no – create relationship type contact customer between the two BP;s /// From Date: System Date /// To Date: 12/29/9999 /// </summary> /// <param name="authorizedContactRequest"></param> /// <param name="bpId"></param> /// <param name="jwt"></param> /// <returns></returns> public async Task <AuthorizedContactResponse> CreateAuthorizedContact(AuthorizedContactRequest authorizedContactRequest, string bpId, string jwt) { _logger.LogInformation($"CreateAuthorizedContact: CreateAuthorizedContact({nameof(authorizedContactRequest)} : {authorizedContactRequest.ToJson()})"); try { var authorizedContactresponse = new AuthorizedContactResponse(); //Do a bp search var bpSearch = MapToBpSearchrequest(authorizedContactRequest.AuthorizedContact); var bpExists = await GetDuplicateBusinessPartnerIfExists(bpSearch); var loggedInBp = bpId.ToString(); if (bpExists == null || !bpExists.MatchFound) { //if bp doesn't exist // create bp //Create a relation ship _logger.LogInformation($"There is not a match for an existing Business Partner based on the information provided."); var bp = await CreateBusinessPartner(authorizedContactRequest.AuthorizedContact); // create bp authorizedContactresponse.BpId = bp.BpId; //Create a Bp relation ship var bpCreateRelation = new CreateBpRelationshipRequest() { FirstAccountBpId = bpId, SecondAccountBpId = bp.BpId, Relationshipcategory = authorizedContactRequest.AuthorizedContact?.Relationshipcategory.GetEnumMemberValue(), TenantBpId = authorizedContactRequest.TenantBpId }; var createRelation = _customerLogic.CreateBpRelationshipAsync(bpCreateRelation, jwt); } else { //if bp exist // check if Bp relation ship exist , if yes update relationship // if no relation ship exist then create a relation ship var contactBp = bpExists.BpId.ToString(); authorizedContactresponse.BpId = bpExists.BpId.ToString(); var bpRelationParam = new BpRelationshipRequestParam() { LoggedInBp = loggedInBp, Jwt = jwt, TenantBp = authorizedContactRequest.TenantBpId }; var checkRelationShip = await GetBprelationships(bpRelationParam); var hasRelation = CheckRelationWithContact(checkRelationShip, contactBp); var hasActiveRelation = IsrelationShipActive(hasRelation); if (hasRelation != null && !hasActiveRelation) { //Update var relationShipToupdate = GetRelationshipToupdate(hasRelation); relationShipToupdate.TenantBpId = ParseBpFromString(authorizedContactRequest.TenantBpId); _mcfClient.UpdateBusinessPartnerRelationship(relationShipToupdate, jwt); } if (hasRelation == null) { //Create Bp relationship var bpCreateRelation = new CreateBpRelationshipRequest() { FirstAccountBpId = bpId, SecondAccountBpId = contactBp, Relationshipcategory = authorizedContactRequest.AuthorizedContact?.Relationshipcategory.GetEnumMemberValue(), TenantBpId = authorizedContactRequest.TenantBpId }; var createRelation = _customerLogic.CreateBpRelationshipAsync(bpCreateRelation, jwt); } } return(authorizedContactresponse); } catch (Exception ex) { _logger.LogError(ex, $"Failed to CreateAuthorizedContact"); throw ex; } }