Exemple #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();
            }
        }
Exemple #2
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);
        }