예제 #1
0
        public ActionResult RemoveCastMember(int id)
        {
            ShowCast model = new ShowCast();

            model.showId = id;
            model.show   = db.Show.Find(id);
            model.cast   = db.Actors.ToList();
            return(View(model));
        }
예제 #2
0
 public ActionResult AddCast(int personId, int showId, string role)
 {
     var entity = new ShowCast(DatabaseSession.Load<Person>(personId), DatabaseSession.Load<Show>(showId), role);
     DatabaseSession.Save(entity);
     return new ViewModelResult(new HttpApiResult
     {
         RedirectToURL = this.GetURL(c => c.PersonDetails(personId)),
     });
 }
예제 #3
0
        public void  getShowsCastByShowID(int id)
        {
            var    apiRes = jsonString("http://api.tvmaze.com/shows/" + id + "/cast");
            JArray jsonResponse = JArray.Parse(apiRes);
            string myId, myName, myBirthday, mygender, myurl;
            var    myList = new List <ShowCast>();

            foreach (var item in jsonResponse)
            {
                myBirthday = myId = mygender = myName = myurl = "";
                var     cnt     = 0;
                JObject jPerson = (JObject)item["person"];
                foreach (var rItem in jPerson)
                {
                    string rItemKey = rItem.Key;
                    string myVal    = rItem.Value.ToString();
                    switch (rItemKey)
                    {
                    case "name":
                        myName = rItem.Value.ToString();
                        cnt++;
                        break;

                    case "birthday":
                        myBirthday = rItem.Value.ToString();
                        cnt++;
                        break;

                    case "id":
                        myId = rItem.Value.ToString();
                        cnt++;
                        break;
                    }
                    if (cnt == 3)
                    {
                        break;
                    }
                }
                //do your save here
                DateTime?myDate = null;
                DateTime outDate;
                if (DateTime.TryParse(myBirthday, out outDate))
                {
                    myDate = outDate;
                }
                var showsCast = new ShowCast
                {
                    name     = myName,
                    birthday = myDate,
                    Castid   = int.Parse(myId),
                    Showsid  = id
                };
                myList.Add(showsCast);
            }
            _ishowCastRepository.SaveShowsCastAsync(myList);
        }
예제 #4
0
        public ActionResult AddCast(int personId, int showId, string role)
        {
            var entity = new ShowCast(DatabaseSession.Load <Person>(personId), DatabaseSession.Load <Show>(showId), role);

            DatabaseSession.Save(entity);
            return(new ViewModelResult(new HttpApiResult
            {
                RedirectToURL = this.GetURL(c => c.PersonDetails(personId)),
            }));
        }
예제 #5
0
        public ActionResult RemoveCastMember(ShowCast model)
        {
            var actor = db.Actors.FirstOrDefault(m => m.id == model.actorId);
            var show  = db.Show.FirstOrDefault(m => m.id == model.showId);

            show.cast.Remove(actor);
            actor.shows.Remove(show);
            db.SaveChanges();
            return(RedirectToAction("Details/" + model.showId, "Shows", new { area = "" }));
        }
예제 #6
0
        private static void ImportCast()
        {
            var cast = oldDatabaseConnection.Query("SELECT * FROM cast").ToList();

            Log("Importing " + cast.Count + " cast");

            using (var session = sessionFactory.OpenSession())
            {
                session.Transaction.Begin();
                session.CreateSQLQuery("SET IDENTITY_INSERT [dbo].ShowCast ON;").ExecuteUpdate();
                var maxId = 0;
                foreach (var _row in cast)
                {
                    if (_row.peepID == null || _row.showID == null)
                    {
                        // broken?
                        continue;
                    }
                    var entity = new ShowCast();
                    entity.ShowCastId = _row.ID;
                    entity.Person     = session.Load <Person>(_row.peepID);
                    entity.Show       = session.Load <Show>(_row.showID);
                    entity.Role       = (_row.role ?? string.Empty).Trim();
                    if (string.IsNullOrWhiteSpace(entity.Role))
                    {
                        continue; // skip
                    }
                    entity.InsertedDateTime     = DateTime.MinValue;
                    entity.LastModifiedDateTime = DateTime.MinValue;
                    if (_row.last_mod != null)
                    {
                        entity.InsertedDateTime     = TimeZoneInfo.ConvertTimeToUtc(_row.last_mod, TimeZoneCode.Eastern.ToTimeZoneInfo());
                        entity.LastModifiedDateTime = TimeZoneInfo.ConvertTimeToUtc(_row.last_mod, TimeZoneCode.Eastern.ToTimeZoneInfo());
                    }
                    session.Save(entity, entity.ShowCastId);
                    if (entity.ShowCastId > maxId)
                    {
                        maxId = entity.ShowCastId;
                    }
                }
                session.Flush();
                session.CreateSQLQuery("SET IDENTITY_INSERT [dbo].ShowCast OFF;").ExecuteUpdate();
                session.CreateSQLQuery("DBCC CHECKIDENT ('dbo.ShowCast', RESEED, " + (maxId + 1) + ")").ExecuteUpdate();
                session.Transaction.Commit();
                session.Close();
            }
        }
예제 #7
0
        public long AddShowsCast(ShowCast b)
        {
            long id = 0;

            try
            {
                var show = ctx.ShowCast.FirstOrDefault(x => x.Castid == b.Castid && x.Showsid == b.Showsid);
                if (show == null)
                {
                    ctx.ShowCast.Add(b);
                    id = ctx.SaveChanges();
                }
            }
            catch (Exception ex)
            {
            }


            return(id);
        }
예제 #8
0
        public void getShowCastPerShow()
        {
            var showlist = _showsRepository.FindAllShows();

            if (showlist != null)
            {
                foreach (var s in showlist)
                {
                    int    id = s.ShowId;
                    var    apiRes = jsonString("http://api.tvmaze.com/shows/" + id + "/cast");
                    JArray jsonResponse = JArray.Parse(apiRes);
                    string myId, myName, myBirthday, mygender;

                    foreach (var item in jsonResponse)
                    {
                        myBirthday = myId = mygender = myName = "";
                        var     cnt     = 0;
                        JObject jPerson = (JObject)item["person"];
                        foreach (var rItem in jPerson)
                        {
                            string rItemKey = rItem.Key;
                            string myVal    = rItem.Value.ToString();
                            switch (rItemKey)
                            {
                            case "name":
                                myName = rItem.Value.ToString();
                                cnt++;
                                break;

                            case "birthday":
                                myBirthday = rItem.Value.ToString();
                                cnt++;
                                break;

                            case "id":
                                myId = rItem.Value.ToString();
                                cnt++;
                                break;
                            }
                            if (cnt == 3)
                            {
                                break;
                            }
                        }
                        //do your save here
                        DateTime?myDate = null;
                        DateTime outDate;
                        if (DateTime.TryParse(myBirthday, out outDate))
                        {
                            myDate = outDate;
                        }
                        var showsCast = new ShowCast
                        {
                            name     = myName,
                            birthday = myDate,
                            Castid   = int.Parse(myId),
                            Showsid  = id
                        };
                        _ishowCastRepository.AddShowsCast(showsCast);
                    }
                }
            }
        }
        public async Task <JsonResult> PairShowsCastsAndPersistData()
        {
            _ShowCastcontext = new ShowCastContext();
            _Castcontext     = new CastContext();
            //Deletes all existing data in the local database first
            _ShowCastcontext.Database.ExecuteSqlCommand("TRUNCATE TABLE [ShowCast]");
            _Castcontext.Database.ExecuteSqlCommand("TRUNCATE TABLE [Cast]");
            string url = "";
            List <ShowWithCast> jSonResult = new List <ShowWithCast>();

            try
            {
                _Castcontext     = new CastContext();
                _ShowCastcontext = new ShowCastContext();

                var shows = from sh in _Showcontext.Show
                            select sh;

                int ShowCastCounter = 0;
                //loop through all the shows
                foreach (Show s in shows)
                {
                    //retrieves every show's cast
                    //Example - http://api.tvmaze.com/shows/1/cast
                    url = "http://api.tvmaze.com/shows/" + s.ShowID + "/cast";

                    using (var client = new HttpClient())
                    {
                        using (var r = await client.GetAsync(new Uri(url)))
                        {
                            string JsonStr2 = await r.Content.ReadAsStringAsync();

                            var result2 = JsonConvert.DeserializeObject <List <CastFull> >(JsonStr2);

                            foreach (CastFull cast in result2)
                            {
                                ShowCastCounter++;
                                Cast aCast = new Cast();
                                aCast.CastID   = cast.person.id;
                                aCast.Name     = cast.person.name;
                                aCast.BirthDay = cast.person.birthday;
                                _Castcontext   = new CastContext();

                                _Castcontext.Add(aCast);
                                await _Castcontext.SaveChangesAsync();

                                ShowCast cs = new ShowCast();
                                cs.ShowCastID    = ShowCastCounter;
                                cs.ShowID        = s.ShowID;
                                cs.CastID        = aCast.CastID;
                                _ShowCastcontext = new ShowCastContext();
                                _ShowCastcontext.Add(cs);
                                await _ShowCastcontext.SaveChangesAsync();
                            }
                        }
                    }
                }
                await _Castcontext.SaveChangesAsync();

                await _ShowCastcontext.SaveChangesAsync();
            }
            catch (Exception ex)
            {
                string error = ex.ToString();
            }

            _Castcontext = new CastContext();
            var casts = from sh in _Castcontext.Cast
                        select sh;

            return(await Task.FromResult(Json(casts)));
        }