Пример #1
0
        /// <summary>
        /// Gets movies for dropdown
        /// </summary>
        /// <returns>List of simple movie data objects</returns>
        public async Task <IEnumerable <MovieForDropdown> > GetForDropdown()
        {
            var movies = await MovieRepo
                         .GetAll()
                         .AsNoTracking()
                         .ToListAsync();

            return(Mapper.Map <IEnumerable <MovieForDropdown> >(movies));
        }
Пример #2
0
        public IActionResult Index()
        {
            IndexViewModel viewModel = new IndexViewModel();

            viewModel.HighRatings   = MovieRepo.GetAll().Where(f => f.Rating.AverageRating >= 70).Take(5).ToList();
            viewModel.All           = MovieRepo.GetAll().ToList();
            viewModel.RecentlyAdded = MovieRepo.GetAll().Take(4).ToList();
            return(View("index", viewModel));
        }
Пример #3
0
        /// <summary>
        /// Gets movie by title and release date
        /// </summary>
        /// <param name="title">Movie title</param>
        /// <param name="date">Movie release date</param>
        /// <returns>Movie details</returns>
        public async Task <MovieDetails> GetMovie(string title, DateTime date)
        {
            var movie = await MovieRepo
                        .GetAll(m => m.Title == title && m.ReleaseDate == date)
                        .FirstOrDefaultAsync();

            var result = Mapper.Map <MovieDetails>(movie);

            return(result);
        }
Пример #4
0
        public IActionResult Filtered(int Id)
        {
            FilteredViewModel viewModel = new FilteredViewModel();

            viewModel.CategoryName = CatRepo.Get(Id)?.Name;
            if (viewModel.CategoryName == null)
            {
                return(NotFound());
            }
            viewModel.Filtered = MovieRepo.GetAll().Where(f => f.Categories.Any(f => f.CategoryId == Id)).ToList();
            return(View(viewModel));
        }
Пример #5
0
        public async Task <bool> UpdateMovie(MovieUpdateRequest request)
        {
            var movie = await MovieRepo
                        .GetAll()
                        .FirstOrDefaultAsync(m => m.Id == request.Id);

            if (movie == null)
            {
                return(false);
            }

            Mapper.Map(request, movie);

            MovieRepo.Update(movie);
            await MovieRepo.SaveChangesAsync();

            return(true);
        }
Пример #6
0
        /// <summary>
        /// Gets movie by id
        /// </summary>
        /// <param name="id">Movie id</param>
        /// <param name="noTracking">Should movie be tacked</param>
        /// <returns>Movie details</returns>
        public async Task <MovieDetails> GetMovie(Guid id, bool noTracking = false)
        {
            var movies = MovieRepo
                         .GetAll()
                         .Include(m => m.Images)
                         .ThenInclude(i => i.Image);

            if (noTracking)
            {
                movies.AsNoTracking();
            }

            var movie = await movies.FirstOrDefaultAsync(m => m.Id == id);

            var result = Mapper.Map <MovieDetails>(movie);

            return(result);
        }
Пример #7
0
        /// <summary>
        /// Gets all movies
        /// </summary>
        /// <returns>List of movies for list/table</returns>
        public async Task <IEnumerable <MovieForList> > GetMovies()
        {
            var movies = await MovieRepo
                         .GetAll()
                         .ToListAsync();

            var result = Mapper.Map <IEnumerable <MovieForList> >(movies);

            foreach (var m in result)
            {
                var thumbnail = await MovieImageRepo
                                .GetAll(i => i.MovieId == m.Id && i.ImageType == MovieImageType.Cover)
                                .Include(i => i.Image)
                                .FirstOrDefaultAsync();

                if (thumbnail != null)
                {
                    m.ThumbnailUrl = thumbnail.Image.Url;
                }
            }

            return(result);
        }
Пример #8
0
        public async Task <OmbiIdentityResult> DeleteUser(string userId)
        {
            var userToDelete = await UserManager.Users.FirstOrDefaultAsync(x => x.Id == userId);

            if (userToDelete != null)
            {
                // Can we delete this user?
                var userRoles = await UserManager.GetRolesAsync(userToDelete);

                if (!CanModifyUser(userRoles))
                {
                    return(Error("You do not have the correct permissions to delete this user"));
                }

                // We need to delete all the requests first
                var moviesUserRequested     = MovieRepo.GetAll().Where(x => x.RequestedUserId == userId);
                var tvUserRequested         = TvRepo.GetChild().Where(x => x.RequestedUserId == userId);
                var musicRequested          = MusicRepo.GetAll().Where(x => x.RequestedUserId == userId);
                var notificationPreferences = _userNotificationPreferences.GetAll().Where(x => x.UserId == userId);
                var userQuality             = await _userQualityProfiles.GetAll().FirstOrDefaultAsync(x => x.UserId == userId);

                if (moviesUserRequested.Any())
                {
                    await MovieRepo.DeleteRange(moviesUserRequested);
                }
                if (tvUserRequested.Any())
                {
                    await TvRepo.DeleteChildRange(tvUserRequested);
                }
                if (musicRequested.Any())
                {
                    await MusicRepo.DeleteRange(musicRequested);
                }
                if (notificationPreferences.Any())
                {
                    await _userNotificationPreferences.DeleteRange(notificationPreferences);
                }
                if (userQuality != null)
                {
                    await _userQualityProfiles.Delete(userQuality);
                }

                // Delete any issues and request logs
                var issues        = _issuesRepository.GetAll().Where(x => x.UserReportedId == userId);
                var issueComments = _issueCommentsRepository.GetAll().Where(x => x.UserId == userId);
                var requestLog    = _requestLogRepository.GetAll().Where(x => x.UserId == userId);
                if (issues.Any())
                {
                    await _issuesRepository.DeleteRange(issues);
                }
                if (requestLog.Any())
                {
                    await _requestLogRepository.DeleteRange(requestLog);
                }
                if (issueComments.Any())
                {
                    await _issueCommentsRepository.DeleteRange(issueComments);
                }

                // Delete the Subscriptions and mobile notification ids
                var subs      = _requestSubscriptionRepository.GetAll().Where(x => x.UserId == userId);
                var mobileIds = _notificationRepository.GetAll().Where(x => x.UserId == userId);
                if (subs.Any())
                {
                    await _requestSubscriptionRepository.DeleteRange(subs);
                }

                if (mobileIds.Any())
                {
                    await _notificationRepository.DeleteRange(mobileIds);
                }

                var result = await UserManager.DeleteAsync(userToDelete);

                if (result.Succeeded)
                {
                    return(new OmbiIdentityResult
                    {
                        Successful = true
                    });
                }

                return(new OmbiIdentityResult
                {
                    Errors = result.Errors.Select(x => x.Description).ToList()
                });
            }
            return(Error("Could not find user to delete."));
        }
Пример #9
0
 public IEnumerable <local.Movie> GetAll()
 {
     return(_repo.GetAll().Select(x => x.toLocal()));
 }
Пример #10
0
        public IActionResult Search(string searchText)
        {
            var searchResult = MovieRepo.GetAll().Where(f => f.Title.Contains(searchText, StringComparison.InvariantCultureIgnoreCase)).ToList();

            return(View(searchResult));
        }
Пример #11
0
 public IActionResult RecentlyAdded()
 {
     return(View(MovieRepo.GetAll().Take(4).ToList()));
 }
Пример #12
0
 public IActionResult HighRatings()
 {
     return(View(MovieRepo.GetAll().Where(f => f.Rating.AverageRating >= 70).Take(5).ToList()));
 }
Пример #13
0
 public List <IDomainObject> GetAll()
 {
     return(ConvertToListOfIdomainObject(MovieRepo.GetAll()));
 }