Ejemplo n.º 1
0
        public static void SetWatched(SiteDB db, long SeriesId, long[] EpisodeIds, long UserId)
        {
            ////take the array of Ids and mark them as watched. Any WatchedEpisodes not in the list should be marked as unwatched by removing them.

            //grab all watched episodes for this series & user.
            List<WatchedEpisode> lstWatchedEpisodes = db.WatchedEpisodes.Where(oo => oo.Episode.SeriesId == SeriesId && oo.UserId == UserId).ToList();

            if (EpisodeIds != null)
            {
                //loop threw new list of watched Episodes
                foreach (long id in EpisodeIds)
                {
                    if (lstWatchedEpisodes.Count(oo => oo.EpisodeId == id) == 0)
                    {
                        //add new record.
                        WatchedEpisode newWatchedEpisode = new WatchedEpisode();
                        newWatchedEpisode.EpisodeId = id;
                        newWatchedEpisode.UserId = UserId;
                        newWatchedEpisode.Created = DateTime.Now;

                        db.WatchedEpisodes.Add(newWatchedEpisode);
                    }
                }
            }

            //delete all records not in new list of watched Episodes
            foreach (WatchedEpisode we in lstWatchedEpisodes.Where(oo => EpisodeIds == null || !EpisodeIds.Contains(oo.EpisodeId)))
            {
                db.WatchedEpisodes.Remove(we);
            }

            //save.
            db.SaveChanges();
        }
Ejemplo n.º 2
0
 public static void SetWatched(SiteDB db, long EpisodeId, long UserId, bool Watched)
 {
     //find the WatchedEpisode record.
     WatchedEpisode watchedEpisode = db.WatchedEpisodes.SingleOrDefault(oo => oo.EpisodeId == EpisodeId && oo.UserId == UserId);
     if (watchedEpisode != null)
     {
         //chech if we should mark watched or unwatched.
         if (!Watched)
         {
             //mark episode unwatched by deleting the WatchedEpisode record.
             db.WatchedEpisodes.Remove(watchedEpisode);
         }
     }
     else if (Watched)
     {
         //mark episode watched by adding a WatchedEpisode record.
         watchedEpisode = new WatchedEpisode();
         watchedEpisode.EpisodeId = EpisodeId;
         watchedEpisode.UserId = UserId;
         watchedEpisode.Created = DateTime.Now;
         db.WatchedEpisodes.Add(watchedEpisode);
     }
     //save changes.
     db.SaveChanges();
 }
Ejemplo n.º 3
0
        public static void SetWatched(SiteDB db, long SeriesId, int Season, long UserId, bool Watched)
        {
            ////take the array of Ids and mark them as watched. Any WatchedEpisodes not in the list should be marked as unwatched by removing them.

            //grab all watched episodes for this series, user, and Season.
            List<WatchedEpisode> lstWatchedEpisodes = db.WatchedEpisodes.Where(oo => oo.Episode.SeriesId == SeriesId && oo.UserId == UserId && oo.Episode.Season == Season).ToList();

            //get list of EpisodeIds based on Season.
            List<long> lstEpisodeIds = new List<long>();

            //get list of EpisodeIds based on Season if we're marking as Watched.
            if (Watched)
            {
                lstEpisodeIds = db.Episodes.Where(oo => oo.SeriesId == SeriesId && oo.Season == Season).Select(oo => oo.EpisodeId).ToList();
            }

            //loop threw new list of watched Episodes
            foreach (long id in lstEpisodeIds)
            {
                if (lstWatchedEpisodes.Count(oo => oo.EpisodeId == id) == 0)
                {
                    //add new record.
                    WatchedEpisode newWatchedEpisode = new WatchedEpisode();
                    newWatchedEpisode.EpisodeId = id;
                    newWatchedEpisode.UserId = UserId;
                    newWatchedEpisode.Created = DateTime.Now;

                    db.WatchedEpisodes.Add(newWatchedEpisode);
                }
            }

            //delete all records not in new list of watched Episodes
            foreach (WatchedEpisode we in lstWatchedEpisodes.Where(oo => !lstEpisodeIds.Contains(oo.EpisodeId)))
            {
                db.WatchedEpisodes.Remove(we);
            }

            //save.
            db.SaveChanges();
        }