示例#1
0
        public void SaveWatchedStatus(bool watched, int userID, DateTime?watchedDate, bool updateWatchedDate)
        {
            AnimeEpisode_UserRepository repEpisodeUsers = new AnimeEpisode_UserRepository();
            AnimeEpisode_User           epUserRecord    = this.GetUserRecord(userID);

            if (watched)
            {
                // lets check if an update is actually required
                if (epUserRecord != null)
                {
                    if (epUserRecord.WatchedDate.HasValue && watchedDate.HasValue &&
                        epUserRecord.WatchedDate.Value.Equals(watchedDate.Value))
                    {
                        // this will happen when we are adding a new file for an episode where we already had another file
                        // and the file/episode was watched already
                        return;
                    }
                }

                if (epUserRecord == null)
                {
                    epUserRecord              = new AnimeEpisode_User();
                    epUserRecord.PlayedCount  = 0;
                    epUserRecord.StoppedCount = 0;
                    epUserRecord.WatchedCount = 0;
                }
                epUserRecord.AnimeEpisodeID = this.AnimeEpisodeID;
                epUserRecord.AnimeSeriesID  = this.AnimeSeriesID;
                epUserRecord.JMMUserID      = userID;
                epUserRecord.WatchedCount++;

                if (watchedDate.HasValue)
                {
                    if (updateWatchedDate)
                    {
                        epUserRecord.WatchedDate = watchedDate.Value;
                    }
                }

                if (!epUserRecord.WatchedDate.HasValue)
                {
                    epUserRecord.WatchedDate = DateTime.Now;
                }

                repEpisodeUsers.Save(epUserRecord);
            }
            else
            {
                if (epUserRecord != null)
                {
                    repEpisodeUsers.Delete(epUserRecord.AnimeEpisode_UserID);
                }
            }
        }
示例#2
0
 public Contract_AnimeEpisode GetUserContract(int userid)
 {
     lock (_lock) //Make it atomic on creation
     {
         AnimeEpisode_User rr = GetUserRecord(userid);
         if (rr != null)
         {
             return(rr.Contract);
         }
         rr                = new AnimeEpisode_User();
         rr.PlayedCount    = 0;
         rr.StoppedCount   = 0;
         rr.WatchedCount   = 0;
         rr.AnimeEpisodeID = this.AnimeEpisodeID;
         rr.AnimeSeriesID  = this.AnimeSeriesID;
         rr.JMMUserID      = userid;
         rr.WatchedDate    = null;
         AnimeEpisode_UserRepository repo = new AnimeEpisode_UserRepository();
         repo.Save(rr);
         return(rr.Contract);
     }
 }