Exemple #1
0
        /// <summary>
        /// Saves a new watching session session and creates a new series/season/episode if necessary
        /// </summary>
        /// <param name="episodeEntry">Aen episode entry</param>
        /// <returns>A JSON representation of a timeline entry</returns>
        public JsonResult QuickSave(TvSerieEpisodeEntry episodeEntry)
        {
            // Used to emulate a failure
            if (episodeEntry.EpisodeTitle == "FAIL") {
                throw new Exception("Une erreur");
            }

            TvWatchingSession watchingSession;
            using (var uow = new UnitOfWork(true)) {
                var serie = uow.TvSeries.FindByTitle(episodeEntry.Title) ?? new TvSerie() { Title = episodeEntry.Title };

                var season = serie.Seasons.SingleOrDefault(x => x.Number == episodeEntry.SeasonNb);
                if (season == null) {
                    season = new TvSerieSeason() { Number = episodeEntry.SeasonNb };
                    serie.AddSeason(season);
                }

                var episode = season.Episodes.SingleOrDefault(x => x.Number == episodeEntry.EpisodeNb);
                if (episode == null) {
                    episode = new TvSerieEpisode() { Number = episodeEntry.EpisodeNb, Title = episodeEntry.EpisodeTitle };
                    season.AddEpisode(episode);
                }

                watchingSession = new TvWatchingSession() { Date = DateTime.ParseExact(episodeEntry.EntryDate, "dd/MM/yyyy", null) };
                episode.AddWatchingSession(watchingSession);

                uow.TvSeries.SaveOrUpdate(serie);
                uow.Commit();
            }

            var timelineEntry = new TimelineEntry(watchingSession, this);
            return Json(timelineEntry);
        }
Exemple #2
0
        /// <summary>
        /// Initializes the entry with a TV watching session
        /// </summary>
        /// <param name="tvWatchingSession">A TV watching session session</param>
        /// <param name="controller">A controller</param>
        private void Initialize(TvWatchingSession tvWatchingSession, Controller controller)
        {
            var episode = tvWatchingSession.Episode;
            var season = episode.Season;
            var serie = season.TvSerie;

            this.ViewUrl = controller.Url.Action("View", "TvSeries", new { id = serie.Id }) + "#tab_saison-" + season.Number;
            this.Title = EscapeString(serie.Title) + " - Saison " + season.Number;
            this.Details = "Ep. " + tvWatchingSession.Episode.Number + " - <em>\"" + EscapeString(episode.Title) + "\"</em>";
            this.ImageUrl = string.IsNullOrEmpty(season.PosterFileName)
                    ? "/Content/images/no_cover.jpg"
                    : "/Content/images/tvSeries/" + season.MediumThumbName;
            this.ImageAlt = this.Title;
        }