async Task <ProfileStoreItems> IProfileStoreService.GetAllProfiles(ProfileStoreFilterOptions profileStoreFilterOptions) { HttpResponseMessage response = null; var profileStoreItems = new ProfileStoreItems(); if (profileStoreFilterOptions == null) { response = await Request(HttpMethod.Get, $"{apiBaseUrl}/{profilesUrl}/"); } else { response = await Request(HttpMethod.Get, $"{apiBaseUrl}/{profilesUrl}/{CreateFilterOptionsUrl(profileStoreFilterOptions)}"); } var getProfiles = await response.Content.ReadAsStringAsync(); if (string.IsNullOrEmpty(getProfiles)) { profileStoreItems = new ProfileStoreItems() { ProfileStoreList = new List <ProfileStoreModel>(), Total = 0, Count = 0 }; } else { profileStoreItems = JsonConvert.DeserializeObject <ProfileStoreItems>(getProfiles); } return(profileStoreItems); }
async Task <TrackEventItems> IProfileStoreService.GetAllTrackEvents(ProfileStoreFilterOptions profileStoreFilterOptions) { HttpResponseMessage response; var trackEventItems = new TrackEventItems(); if (profileStoreFilterOptions == null) { response = await Request(HttpMethod.Get, $"{apiBaseUrl}/{trackEventsUrl}/"); } else { var uri = $"{apiBaseUrl}/{trackEventsUrl}/{CreateFilterOptionsUrl(profileStoreFilterOptions)}"; response = await Request(HttpMethod.Get, uri); } var getTrackEvents = await response.Content.ReadAsStringAsync(); if (string.IsNullOrEmpty(getTrackEvents)) { trackEventItems = new TrackEventItems() { TrackEventList = new List <TrackEventModel>(), Total = 0, Count = 0 }; } else { trackEventItems = JsonConvert.DeserializeObject <TrackEventItems>(getTrackEvents); } return(trackEventItems); }
/// <summary> /// Creates the filter option URL. /// </summary> /// <param name="profileStoreFilterOptions">The profile store filter options.</param> /// <returns>Part of Profile Store Api URL.</returns> private string CreateFilterOptionsUrl(ProfileStoreFilterOptions profileStoreFilterOptions) { var hasFilterOptions = false; var urlSuffix = new StringBuilder(); urlSuffix.Append("?"); if (!string.IsNullOrEmpty(profileStoreFilterOptions.Filter.Key)) { if (hasFilterOptions == true) { urlSuffix.Append("&"); } urlSuffix.Append($"$filter={profileStoreFilterOptions.Filter.Key} eq {profileStoreFilterOptions.Filter.Value}"); hasFilterOptions = true; } if (profileStoreFilterOptions.Skip != 0) { if (hasFilterOptions == true) { urlSuffix.Append(" &"); } urlSuffix.Append($"$skip={profileStoreFilterOptions.Skip}"); hasFilterOptions = true; } if (profileStoreFilterOptions.Top != 0) { if (hasFilterOptions == true) { urlSuffix.Append(" &"); } urlSuffix.Append($"$top={profileStoreFilterOptions.Top}"); hasFilterOptions = true; } if (!string.IsNullOrEmpty(profileStoreFilterOptions.OrderBy.Key)) { if (hasFilterOptions == true) { urlSuffix.Append(" &"); } urlSuffix.Append($"$orderby={profileStoreFilterOptions.OrderBy.Key} {profileStoreFilterOptions.OrderBy.Value}"); hasFilterOptions = true; } return(urlSuffix.ToString()); }