public async Task <IActionResult> CreateBpRelationship([FromBody] CreateBpRelationshipRequest request) { IActionResult result; try { _logger.LogInformation($"CreateBpRealtionship({nameof(request)}: {request.ToJson()})"); HttpContext.Request.Headers.TryGetValue("Authorization", out StringValues jwt); //Call Logic Class to create bp relationship and returns true or false if successful/not successful var response = _customerLogic.CreateBpRelationshipAsync(request, jwt); result = Ok(response); } catch (Exception e) { _logger.LogError(e, e.Message); result = e.ToActionResult(); } return(result); }
/// <summary> /// Creates BpReationship /// </summary> /// <param name="request"></param> /// <param name="jwt"></param> /// <returns></returns> public bool CreateBpRelationshipAsync(CreateBpRelationshipRequest request, string jwt) { var fromDate = DateTimeOffset.UtcNow.ToString("yyyy-MM-ddTHH:mm:ss"); var toDate = DateTimeOffset.MaxValue.ToUniversalTime().ToString("yyyy-MM-ddTHH:mm:ss"); var mcfRequest = new BpRelationshipRequest() { AccountID1 = request.FirstAccountBpId, AccountID2 = request.SecondAccountBpId, Relationshipcategory = request.Relationshipcategory, Differentiationtypevalue = "", Defaultrelationship = false, Validfromdatenew = DateTime.Parse(fromDate), Validtodatenew = DateTime.Parse(toDate), }; var response = _mcfClient.CreateBpRelationship(jwt, mcfRequest, request.TenantBpId); return(response); }
/// <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; } }