示例#1
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();
            }
        }
示例#2
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
                });
            }
        }
示例#3
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);
        }