Ejemplo n.º 1
0
        static void Main(string[] args)
        {
            string getURI       = "https://candidate.hubteam.com/candidateTest/v3/problem/dataset?userKey=c6ecf2ff937d313d57b670b147f4";
            string postURI      = "https://candidate.hubteam.com/candidateTest/v3/problem/result?userKey=c6ecf2ff937d313d57b670b147f4";
            var    inputFromAPI =// "{            \"partners\": [          {            \"firstName\": \"Darin\",            \"lastName\": \"Daignault\",            \"email\": \"[email protected]\",            \"country\": \"United States\",            \"availableDates\": [            \"2017-05-03\",            \"2017-05-06\"            ]          },          {            \"firstName\": \"Crystal\",            \"lastName\": \"Brenna\",            \"email\": \"[email protected]\",            \"country\": \"Ireland\",            \"availableDates\": [            \"2017-04-27\",            \"2017-04-29\",            \"2017-04-30\"            ]          },          {            \"firstName\": \"Janyce\",            \"lastName\": \"Gustison\",            \"email\": \"[email protected]\",            \"country\": \"Spain\",            \"availableDates\": [            \"2017-04-29\",            \"2017-04-30\",            \"2017-05-01\"            ]          },          {            \"firstName\": \"Tifany\",            \"lastName\": \"Mozie\",            \"email\": \"[email protected]\",            \"country\": \"Spain\",            \"availableDates\": [            \"2017-04-28\",            \"2017-04-29\",            \"2017-05-01\",            \"2017-05-04\"            ]          },          {            \"firstName\": \"Temple\",            \"lastName\": \"Affelt\",            \"email\": \"[email protected]\",            \"country\": \"Spain\",            \"availableDates\": [            \"2017-04-28\",            \"2017-04-29\",            \"2017-05-02\",            \"2017-05-04\"            ]          },          {            \"firstName\": \"Robyn\",            \"lastName\": \"Yarwood\",            \"email\": \"[email protected]\",            \"country\": \"Spain\",            \"availableDates\": [            \"2017-04-29\",            \"2017-04-30\",            \"2017-05-02\",            \"2017-05-03\"            ]          },          {            \"firstName\": \"Shirlene\",            \"lastName\": \"Filipponi\",            \"email\": \"[email protected]\",            \"country\": \"Spain\",            \"availableDates\": [            \"2017-04-30\",            \"2017-05-01\"            ]          },          {            \"firstName\": \"Oliver\",            \"lastName\": \"Majica\",            \"email\": \"[email protected]\",            \"country\": \"Spain\",            \"availableDates\": [            \"2017-04-28\",            \"2017-04-29\",            \"2017-05-01\",            \"2017-05-03\"            ]          },          {            \"firstName\": \"Wilber\",            \"lastName\": \"Zartman\",            \"email\": \"[email protected]\",            \"country\": \"Spain\",            \"availableDates\": [            \"2017-04-29\",            \"2017-04-30\",            \"2017-05-02\",            \"2017-05-03\"            ]          },          {            \"firstName\": \"Eugena\",            \"lastName\": \"Auther\",            \"email\": \"[email protected]\",            \"country\": \"United States\",            \"availableDates\": [            \"2017-05-04\",            \"2017-05-09\"            ]          }            ]          }";
                                  APIcall(HttpMethod.Get, getURI).Result;
            Hubspotinput resultOfAPI = JsonConvert.DeserializeObject <Hubspotinput>(inputFromAPI);

            var apipost = APIcall(HttpMethod.Post, postURI, ProcessData(resultOfAPI)).Result;
        }
Ejemplo n.º 2
0
        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);
        }