Ejemplo n.º 1
0
        /// <summary>
        /// Set person
        /// </summary>
        /// <param name="person">Instance of Person </param>
        private void SetPerson(Person person)
        {
            // retrieve profile data linkedin
            dynamic data = RetrieveProfileData();

            JObject jObj = JObject.Parse(data);

            // set data of instance of Person
            person.Id = (string)jObj.OfType<JProperty>().Where(p => p.Name == "id").First().Value;
            person.FirstName = (string)jObj.OfType<JProperty>().Where(p => p.Name == "firstName").First().Value;

            // set data of instance of Education
            IEnumerable<JToken> educations = jObj.OfType<JProperty>().Where(p => p.Name == "educations").Descendants();

            foreach (JToken jToken in educations.OfType<JProperty>().Where(p => p.Name == "values").Children().First().Children())
            {
                JEnumerable<JToken> values = jToken.Children();
                Education education = new Education();
                education.Id = int.Parse(values.OfType<JProperty>().Where(p => p.Name == "id").First().Value.ToString());
                education.SchoolName = values.OfType<JProperty>().Where(p => p.Name == "schoolName").First().Value.ToString();
                education.Degree = values.OfType<JProperty>().Where(p => p.Name == "degree").First().Value.ToString();
                education.StartDate = values.OfType<JProperty>().Where(p => p.Name == "startDate").Any() ? new DateTime(int.Parse(values.OfType<JProperty>().Where(p => p.Name == "startDate").First().Descendants().OfType<JProperty>().Where(p => p.Name == "year").First().Value.ToString()), 1, 1, 0, 0, 0) : DateTime.MinValue;
                education.EndDate = values.OfType<JProperty>().Where(p => p.Name == "endDate").Any() ? new DateTime(int.Parse(values.OfType<JProperty>().Where(p => p.Name == "endDate").First().Descendants().OfType<JProperty>().Where(p => p.Name == "year").First().Value.ToString()), 1, 1, 0, 0, 0) : DateTime.MinValue;

                person.Educations.Add(education);
            }
            // set data of instance of Skill
            IEnumerable<JToken> skills = jObj.OfType<JProperty>().Where(p => p.Name == "skills").Descendants();

            foreach (JToken jToken in skills.OfType<JProperty>().Where(p => p.Name == "values").Children().First().Children())
            {
                JEnumerable<JToken> values = jToken.Children();
                Skill skill = new Skill();
                skill.Id = int.Parse(values.OfType<JProperty>().Where(p => p.Name == "id").First().Value.ToString());
                skill.Name = values.OfType<JProperty>().Where(p => p.Name == "skill").First().Descendants().OfType<JProperty>().Where(p => p.Name == "name").First().Value.ToString();
                person.Skills.Add(skill);
            }
        }
Ejemplo n.º 2
0
 public LinkedInModels()
 {
     Person = new Person();
     SetPerson(Person);
 }