public bool IsHPIDCustomerProfileUpdateRequired(CustomerData custData, HPIDCustomerProfile source, bool SupportUpdateToProfileDetails) { if (source == null || custData == null) { return(false); } //Check for changes in all HPID fields { SelectOperationForName(source.name, custData.FirstName, custData.LastName); SelectOperationForEmail(source.emails, custData.EmailAddress); SelectOperationForLocalization(source.locale, custData); SelectOperationForCountryResidence(source.countryResidence, custData.Country); SelectOperationForCompanyName(source.hpp_organizationName, custData.CompanyName); //Remove possibility of updating/ removing addresses(Addresses node) //Remove possibility of updating/ removing phones(PhoneNumbers node) if (SupportUpdateToProfileDetails) { SelectOperationForDisplayName(source.displayName, custData.DisplayName); SelectOperationForGender(source.gender, custData.Gender); } //Support old profile update and new Profile update. SelectOperationForAddress(source.addresses, custData); } return(operations.Count > 0 || removals.Count > 0); }
public HPIDCustomerProfile GetProfile(string token) { JObject respObj = null; var client = new HttpClient(); client.DefaultRequestHeaders.TryAddWithoutValidation("content-type", "application/x-www-form-urlencoded"); client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json")); client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", token); Stopwatch timer = new Stopwatch(); string respResult = null; ResponseBase response = new ResponseBase(); try { timer.Start(); var resp = client.GetAsync(profileURL).Result; timer.Stop(); respResult = resp.Content.ReadAsStringAsync().Result; respObj = JObject.Parse(respResult); if (!CheckServiceResponse(respObj, response)) { return(null); } } catch (Exception) { return(null); } finally { timer.Stop(); // Log the outbound service call details in ExtServiceLogs table ExtServiceLogs.LogExtServiceCallDetails(client?.DefaultRequestHeaders?.Authorization?.ToString(), HttpVerbs.Get, "HPID", profileURL?.ToString(), null, respObj?.ToString(), (int)timer.ElapsedMilliseconds, false); } if (string.IsNullOrEmpty((string)respObj["id"])) { return(null); } HPIDCustomerProfile profile = new HPIDCustomerProfile(); try { var fName = (string)respObj["name"]["familyName"]; var gName = (string)respObj["name"]["givenName"]; profile.name = new Name() { familyName = fName, givenName = gName }; } catch (Exception) { }; profile.countryResidence = (string)respObj["countryResidence"]; profile.locale = (string)respObj["locale"]; profile.hpp_organizationName = (string)respObj["hpp_organizationName"]; //Add DisplayName try { profile.displayName = (string)respObj["displayName"]; } catch (Exception ex) { profile.displayName = null; log.Debug($"GetIdsAndProfile: Errortype=HPID response parse-DisplayName, exception={ex.Message}"); } //Add gender try { profile.gender = (string)respObj["gender"]; } catch (Exception ex) { profile.gender = null; log.Debug($"GetIdsAndProfile: Errortype=HPID response parse-Gender, exception={ex.Message}"); } try { JToken jStatus = respObj.SelectToken("$.emails"); if (jStatus != null && jStatus.Count() > 0) { if (profile.emails == null) { profile.emails = new List <Email>(); } foreach (var i in jStatus) { Email eml = i.ToObject <Email>(); if (eml != null) { profile.emails.Add(eml); } } } } catch (Exception) { }; //Get all addresses try { JToken jStatus = respObj.SelectToken("$.addresses"); if (jStatus != null && jStatus.Count() > 0) { if (profile.addresses == null) { profile.addresses = new List <Address>(); } foreach (var i in jStatus) { Address adr = i.ToObject <Address>(); if (adr != null) { profile.addresses.Add(adr); } } } } catch (Exception) { }; //Get all phonenumbers try { JToken jStatus = respObj.SelectToken("$.phoneNumbers"); if (jStatus != null && jStatus.Count() > 0) { profile.phoneNumbers = new List <PhoneNumber>(); foreach (var i in jStatus) { PhoneNumber ph = i.ToObject <PhoneNumber>(); profile.phoneNumbers.Add(ph); } } } catch (Exception ex) { log.Debug($"GetIdsAndProfile: Errortype=HPID response parse-phoneNumbers, exception={ex.Message}"); } return(profile); }