Exemple #1
0
        public List <FilmViewModel> GetAllFilms(string userId)
        {
            var films = new List <FilmViewModel>();

            var userFilm    = GetUserFilmViewModel();
            var generalFilm = GetGeneralFilmViewModel();

            foreach (var film in FilmHausDbContext.Films.ToList())
            {
                var result = new FilmViewModel();

                if (UserFilmRatingService.DoesUserHaveRating(userId, film.MediaId))
                {
                    result = userFilm.Invoke(film.UserFilms
                                             .Where(uf => uf.Id == userId && uf.MediaId == film.MediaId)
                                             .FirstOrDefault()
                                             );
                }
                else
                {
                    result = generalFilm.Invoke(film);
                    result.InCurrentUserLibrary = UserFilmService.IsFilmInLibrary(film.MediaId, userId);
                }

                films.Add(result);
            }

            return(films);
        }
Exemple #2
0
        public FilmViewModel GetFilmByMediaId(string userId, Guid mediaId)
        {
            var film = FilmHausDbContext.Films.AsExpandable().Where(f => f.MediaId == mediaId).FirstOrDefault();

            var userFilm    = GetUserFilmViewModel();
            var generalFilm = GetGeneralFilmViewModel();

            if (UserFilmRatingService.DoesUserHaveRating(userId, film.MediaId))
            {
                return(userFilm.Invoke(film.UserFilms
                                       .Where(uf => uf.Id == userId && uf.MediaId == film.MediaId)
                                       .FirstOrDefault()
                                       ));
            }
            else
            {
                var result = generalFilm.Invoke(film);
                result.InCurrentUserLibrary = UserFilmService.IsFilmInLibrary(mediaId, userId);

                return(result);
            }
        }