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

            WatchingSession watchingSession;
            using (var uow = new UnitOfWork(true)) {
                var movie = uow.Movies.FindByTitle(movieEntry.Title) ??
                            new Movie() { Title = movieEntry.Title, Director = movieEntry.Director };

                watchingSession = new WatchingSession() { Date = DateTime.ParseExact(movieEntry.EntryDate, "dd/MM/yyyy", null) };
                movie.AddWatchingSession(watchingSession);

                uow.Movies.SaveOrUpdate(movie);
                uow.Commit();
            }

            var timelineEntry = new TimelineEntry(watchingSession, this);
            return Json(timelineEntry);
        }
Exemple #2
0
 /// <summary>
 /// Initializes the entry with a watching session
 /// </summary>
 /// <param name="watchingSession">A watching session</param>
 /// <param name="controller">A controller</param>
 private void Initialize(WatchingSession watchingSession, Controller controller)
 {
     this.ViewUrl = controller.Url.Action("View", "Movies", new { id = watchingSession.Movie.Id });
     this.Title = EscapeString(watchingSession.Movie.Title);
     this.Details = string.IsNullOrEmpty(watchingSession.Movie.ReleaseDate)
             ? EscapeString(watchingSession.Movie.Director)
             : EscapeString(watchingSession.Movie.Director + ", " + watchingSession.Movie.ReleaseDate);
     this.ImageUrl = string.IsNullOrEmpty(watchingSession.Movie.PosterFileName)
             ? "/Content/images/no_cover.jpg"
             : "/Content/images/movies/" + watchingSession.Movie.MediumThumbName;
     this.ImageAlt = EscapeString("Poster de " + watchingSession.Movie.Title);
 }