public ActionResult ReloadShows()
        {
            var rezult = getUriData("http://api.tvmaze.com/shows");


            List <TVMazeShow> ShowList = new List <TVMazeShow>();

            dynamic jsonObj = JsonConvert.DeserializeObject(rezult);

            var x = 0;

            foreach (var obj in jsonObj)
            {
                var aTVShow = new TVMazeShow();

                x++;
                // Filter for several TV Shows only
                if (x == 24 || x == 25 || x == 26 || x == 32 || x == 73 || x == 115 || x == 163 || x == 167 || x == 176 || x == 189)
                {
                    continue;
                }


                if (obj.name != null)
                {
                    aTVShow.id        = (int)x; //(int)obj.id;
                    aTVShow.name      = (string)obj.name;
                    aTVShow.status    = (string)obj.status;
                    aTVShow.runtime   = (int)obj.runtime;
                    aTVShow.premiered = (string)obj.premiered;

                    aTVShow.day     = (string)obj.schedule.days[0];
                    aTVShow.time    = (string)obj.schedule.time;
                    aTVShow.status  = (string)obj.status;
                    aTVShow.network = (string)obj.network.name;

                    var     tempRating = (string)obj.rating.average;
                    decimal?tvrating   = !string.IsNullOrEmpty(tempRating) ?
                                         decimal.Parse(tempRating.Replace(",", "")) :
                                         (decimal?)null;

                    aTVShow.rating = tvrating;  //(decimal)obj.rating.average;
                    aTVShow.photo  = (string)obj.image.original;

                    using (var dbc = new VIDEAEntities())
                    {
                        dbc.TVMazeShows.Add(aTVShow);
                        dbc.SaveChanges();
                    }
                }
            }

            return(RedirectToAction("Index"));
        }
        // GET: TVMazeShows/Details/5
        public ActionResult Details(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            TVMazeShow tVMazeShow = db.TVMazeShows.Find(id);

            if (tVMazeShow == null)
            {
                return(HttpNotFound());
            }
            return(View(tVMazeShow));
        }
Ejemplo n.º 3
0
        private async Task <IEnumerable <TVMazePerson> > LoadShowCasts(TVMazeShow show)
        {
            var result = new List <Task <TVMazePerson> >();

            var castsListJson = JArray.Parse(await _tvMazeApiService.GetCastsAsync(show.Id).ConfigureAwait(false));

            castsListJson.ToList().ForEach(castJson =>
            {
                var cast = JsonConvert.DeserializeObject <TVMazePerson>(castJson["person"].ToString());
                result.Add(Task.FromResult(cast));
            });


            return(await Task.WhenAll(result));
        }