static async Task <string> APIcall(HttpMethod method, string uri, HubspotOutput r = null, Dictionary <string, string> RequestHeader = null) { HttpClient client = new HttpClient(); // Add a new Request Message HttpRequestMessage requestMessage = new HttpRequestMessage(method, uri); // Add our custom headers if (RequestHeader != null) { foreach (var item in RequestHeader) { requestMessage.Headers.Add(item.Key, item.Value); } } if (method == HttpMethod.Post) { requestMessage.Content = new StringContent(JsonConvert.SerializeObject(r), Encoding.UTF8, "application/json"); } HttpResponseMessage response = await client.SendAsync(requestMessage); var responseString = await response.Content.ReadAsStringAsync(); return(responseString); }
static HubspotOutput ProcessData(Hubspotinput input) { HubspotOutput hubspotOutput = new HubspotOutput(); hubspotOutput.countries = new List <Country>(); Dictionary <string, SortedSet <DateTime> > CountryandDates = new Dictionary <string, SortedSet <DateTime> >(); foreach (var partner in input.partners) { if (!CountryandDates.ContainsKey(partner.country)) { CountryandDates[partner.country] = new SortedSet <DateTime>(); } foreach (var date in partner.availableDates) { var availableDate = DateTime.ParseExact(date, "yyyy-MM-dd", System.Globalization.CultureInfo.InvariantCulture); if (!CountryandDates[partner.country].Contains(availableDate)) { CountryandDates[partner.country].Add(availableDate); } } } foreach (KeyValuePair <string, SortedSet <DateTime> > entry in CountryandDates) { List <Partner> partners = input.partners.Where(x => x.country == entry.Key).ToList(); List <Partner> partnersdatemax = new List <Partner>(); string dateval1 = null; foreach (var date in entry.Value) { List <Partner> partnersdate1 = new List <Partner>(); //partners.Where(x => x.availableDates.Where(y => y.Equals(date.Date.ToString())).ToList().Count>0).ToList(); foreach (var partner in partners) { if (partner.availableDates.Contains(date.Date.ToString("yyyy-MM-dd")) && partner.availableDates.Contains(date.AddDays(1).ToString("yyyy-MM-dd"))) { partnersdate1.Add(partner); } } if (partnersdatemax.Count < partnersdate1.Count) { partnersdatemax = partnersdate1; dateval1 = date.Date.ToString("yyyy-MM-dd"); } } var country = new Country(); country.attendees = new List <string>(); if (partnersdatemax.Count == 0) { country.attendeeCount = 0; country.startDate = null; } else { country.attendeeCount = partnersdatemax.Count(); country.startDate = dateval1; foreach (var partner in partnersdatemax) { country.attendees.Add(partner.email); } } country.name = entry.Key; hubspotOutput.countries.Add(country); } return(hubspotOutput); }