Ejemplo n.º 1
0
 public static async Task InitializeAsync()
 {
     using (var db = new PlayHistoryDbContext())
     {
         await db.Database.EnsureCreatedAsync();
     }
 }
Ejemplo n.º 2
0
        public static void VideoPlayed(string rawVideoId)
        {
            using (var db = new PlayHistoryDbContext())
            {
                VideoPlayHistory videoHistory = null;
                try
                {
                    videoHistory = db.VideoPlayHistory.SingleOrDefault(x => x.RawVideoId == rawVideoId);
                }
                catch { }

                if (videoHistory == null)
                {
                    videoHistory = new VideoPlayHistory()
                    {
                        RawVideoId = rawVideoId,
                        PlayCount  = 1,
                        LastPlayed = DateTime.Now
                    };

                    db.VideoPlayHistory.Add(videoHistory);
                }
                else
                {
                    videoHistory.PlayCount++;
                    videoHistory.LastPlayed = DateTime.Now;
                    db.VideoPlayHistory.Update(videoHistory);
                }

                db.SaveChanges();
            }
        }
Ejemplo n.º 3
0
        public static VideoPlayHistory Get(string rawVideoId)
        {
            using (var db = new PlayHistoryDbContext())
            {
                VideoPlayHistory history = null;
                try
                {
                    history = db.VideoPlayHistory.SingleOrDefault(x => x.RawVideoId == rawVideoId);
                } catch { }

                return(new VideoPlayHistory()
                {
                    LastPlayed = history?.LastPlayed ?? DateTime.MinValue,
                    PlayCount = history?.PlayCount ?? 0,
                    RawVideoId = rawVideoId
                });
            }
        }
Ejemplo n.º 4
0
        public static bool RemoveHistory(string rawVideoId)
        {
            bool removeSuccess = false;

            using (var db = new PlayHistoryDbContext())
            {
                VideoPlayHistory videoHistory = null;
                try
                {
                    videoHistory = db.VideoPlayHistory.SingleOrDefault(x => x.RawVideoId == rawVideoId);
                }
                catch { }

                if (videoHistory != null)
                {
                    db.VideoPlayHistory.Remove(videoHistory);
                    db.SaveChanges();
                    removeSuccess = true;
                }
            }

            return(removeSuccess);
        }