示例#1
0
        public IActionResult PopulateSocialMedia()
        {
            All_Social_Media sMedia = GetSocialMedia();

            foreach (Social_Media s in sMedia.Results)
            {
                if (dbContext.Social_Media.Where(c => c.Id.Equals(s.Id)).Count() == 0)
                {
                    foreach (Agencies a in s.agencies)
                    {
                        //    if (dbContext.Agencies.Where(d => d.id.Equals(a.id)).Count() == 0)
                        //    {
                        dbContext.Agencies.Add(a);
                        //    }
                    }
                    foreach (Tags t in s.tags)
                    {
                        //    if (dbContext.Tags.Where(b => b.id.Equals(t.id)).Count() == 0)
                        //    {
                        dbContext.Tags.Add(t);
                        //    }
                    }
                    dbContext.Social_Media.Add(s);
                }
            }
            dbContext.SaveChanges();
            ViewBag.dbSuccessComp = 1;
            return(View("SocialMedia", sMedia.Results));
        }
示例#2
0
        public All_Social_Media GetSocialMedia()
        {
            string SocialMedia_API_PATH = BASE_URL + "v1/social_media.json";

            All_Social_Media socialMedia = null;

            // Connect to the API and retrieve information
            httpClient.BaseAddress = new Uri(SocialMedia_API_PATH);
            HttpResponseMessage response = httpClient.GetAsync(SocialMedia_API_PATH).GetAwaiter().GetResult();

            // Read the Json objects in the API response
            if (response.IsSuccessStatusCode)
            {
                socialMediaList = response.Content.ReadAsStringAsync().GetAwaiter().GetResult();
            }

            // Parse the Json strings as C# objects
            if (!socialMediaList.Equals(""))
            {
                /*try
                 * {
                 *  JsonSerializerSettings settings = new JsonSerializerSettings();
                 *  settings.MissingMemberHandling = MissingMemberHandling.Error;*/

                socialMedia = JsonConvert.DeserializeObject <All_Social_Media>(socialMediaList);//, settings);

                /*}
                 * catch (Exception ex)
                 * {
                 *  Debug.WriteLine(ex.GetType().Name + ": " + ex.Message);
                 * }*/
            }

            return(socialMedia);
        }
示例#3
0
        public IActionResult SocialMedia()
        {
            //Set ViewBag variable first
            ViewBag.dbSuccessComp = 0;
            All_Social_Media sMedia = GetSocialMedia();

            return(View(sMedia.Results));
        }