Esempio n. 1
0
 public static async Task InitializeAsync()
 {
     using (var db = new PlayHistoryDbContext())
     {
         await db.Database.EnsureCreatedAsync();
     }
 }
Esempio 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();
            }
        }
Esempio 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
                });
            }
        }
Esempio 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);
        }