Пример #1
0
        // Converts from EF domain model to view model
        private View.Movie ConvertMovie(Domain.Movie movie)
        {
            var viewModelMovie = new View.Movie();

            viewModelMovie.Id              = movie.Id;
            viewModelMovie.Title           = movie.Title;
            viewModelMovie.Year            = movie.Year;
            viewModelMovie.Genres          = movie.Genres.Select(g => g.GenreValue.ToString());
            viewModelMovie.AmountOfRatings = movie.Ratings.Where(r => r.MovieId == movie.Id).Count();
            viewModelMovie.Poster          = movie.Poster;
            viewModelMovie.ContentRating   = movie.ContentRating;
            viewModelMovie.Duration        = movie.Duration;
            viewModelMovie.ReleaseDate     = movie.ReleaseDate;
            viewModelMovie.OriginalTitle   = movie.OriginalTitle;
            viewModelMovie.Storyline       = movie.Storyline;
            viewModelMovie.Actors          = movie.Actors.Select(a => a.Actor.Name);
            viewModelMovie.ImdbRating      = movie.ImdbRating;
            viewModelMovie.PosterURL       = movie.PosterURL;
            viewModelMovie.Comments        = movie.Comments.Select(c => new View.Comment()
            {
                Text    = c.Text,
                Author  = c.Author,
                Id      = c.Id,
                MovieId = c.Movie.Id,
                Date    = c.Date,
            });

            //Can not call Average() on empty collection
            viewModelMovie.AverageRating = movie.Ratings.Count == 0 ? 0 : movie.Ratings.Average(r => r.RatingValue);

            return(viewModelMovie);
        }
Пример #2
0
        public bool IsFavorite(string username, View.Movie movie)
        {
            // Find movie
            var movies = DB.Movies
                         .Include(m => m.Favorites)
                         .FirstOrDefault(m => m.Id == movie.Id);

            // Check if movie exists, if so check if user has favorited it
            if (movies != null)
            {
                foreach (var f in movies.Favorites)
                {
                    if (f.Username == username)
                    {
                        return(true);
                    }
                }
            }
            return(false);
        }
Пример #3
0
        private static View.Movie DomainMovieToViewMovie(Domain.Movie domainMovie)
        {
            var viewMovie = new View.Movie()
            {
                Id              = domainMovie.Id.Pid,
                Title           = domainMovie.Title,
                Year            = domainMovie.Year,
                Genres          = domainMovie.Genres,
                AmountOfRatings = domainMovie.Ratings.Count,
                Poster          = domainMovie.Poster,
                ContentRating   = domainMovie.ContentRating,
                Duration        = domainMovie.Duration,
                ReleaseDate     = domainMovie.ReleaseDate,
                AverageRating   = domainMovie.AverageRating,
                OriginalTitle   = domainMovie.OriginalTitle,
                Storyline       = domainMovie.Storyline,
                Actors          = domainMovie.Actors,
                ImdbRating      = domainMovie.ImdbRating,
                PosterURL       = domainMovie.PosterURL,
            };

            return(viewMovie);
        }
Пример #4
0
 public bool IsFavorite(string username, View.Movie movie)
 {
     throw new NotImplementedException();
 }