コード例 #1
0
        public async Task <IViewComponentResult> InvokeAsync(SortBy sortBy)
        {
            var now = DateTime.Now;

            string key = "";

            switch (sortBy)
            {
            //case SortBy.Day:

            //    key = string.Format(ModelCacheEventConsumer.MOVIES_BY_PERIODS_KEY, nameof(SortBy.Day));
            //    var cachedDayEntry = await _cacheManager.Get(key, async () =>
            //     {
            //         var movies = await _movieService.GetAllMovies();
            //         if (movies == null) return null;
            //         return movies.Where(w => w.Year == now.Year &&
            //         w.UpdatedDate.Month == now.Month &&
            //         w.UpdatedDate.Day == now.Day)
            //        .OrderByDescending(m => m.View).Take(10).Select(x => PrepareMovieModel(x));
            //     });
            //    return View(cachedDayEntry);
            case SortBy.Week:
                // use cache here crash the EF
                key = string.Format(ModelCacheEventConsumer.MOVIES_BY_PERIODS_KEY, nameof(SortBy.Week));
                var cachedWeekEntry = await _cacheManager.Get(key, async() =>
                {
                    var movies = await _movieService.SearchMoviesWithAsync("", pageSize: 10, sortBy: (int)SortBy.Week);
                    if (movies == null)
                    {
                        return(null);
                    }
                    return(movies.Select(x => _movieModelFactory.PrepareMovieModel(x, 100, false)).ToList());
                    //.Where(w => IsDayInWeek(w.UpdatedDate))
                    //    .OrderByDescending(m => m.View).Take(10).Select(x => PrepareMovieModel(x));
                });

                return(View(cachedWeekEntry));

            case SortBy.Month:
                key = string.Format(ModelCacheEventConsumer.MOVIES_BY_PERIODS_KEY, nameof(SortBy.Month));
                var cachedMonthEntry = await _cacheManager.Get(key, async() =>
                {
                    var movies2 = await _movieService.SearchMoviesWithAsync("", pageSize: 10, sortBy: (int)SortBy.Month);
                    if (movies2 == null)
                    {
                        return(null);
                    }
                    return(movies2.Select(x => _movieModelFactory.PrepareMovieModel(x, 100, false)).ToList());
                });

                return(View(cachedMonthEntry));
            }
            return(View(null));
        }
コード例 #2
0
        public async Task <IViewComponentResult> InvokeAsync()
        {
            string key = string.Format(ModelCacheEventConsumer.RECOMMENDED_MOVIES);

            var cacheEntry = _cacheManager.Get(key, () => {
                var model = _movieService.GetRecommendedMovies()
                            .Select(x => _movieModelFactory.PrepareMovieModel(x)).ToList();
                return(model);
            });

            return(View(cacheEntry));
        }
コード例 #3
0
        public JsonResult Get(int id)
        {
            var list       = new List <MovieModel>();
            var MovieModel = new MovieModel();
            var Movie      = _movieService.GetMovieById(id);
            var host       = Request.Host.Value;

            if (MovieModel != null)
            {
                MovieModel = _movieModelFactory.PrepareMovieModel(Movie, host);
            }
            list.Add(MovieModel);
            return(Json(list));
        }
コード例 #4
0
        private async Task <List <MoviesOnCategoriesModel> > LoadMovie(int categoryId      = 0,
                                                                       bool showOnHomePage = false, int pageIndex = 1, int pageSize = 12)
        {
            var model = new List <MoviesOnCategoriesModel>();

            try
            {
                var categories = _categoryService.Categories(showOnHomePage);
                foreach (var item in categories)
                {
                    var subs             = _categoryService.Categories().Where(c => c.ParentCategoryId == item.Id);
                    var moviesOnCategory = new MoviesOnCategoriesModel()
                    {
                        CategoryName   = item.Name,
                        CategoryId     = item.Id,
                        CategorySeName = item.GetSeName(),
                        Categories     = PrepareCategoryModel(subs.ToList())
                    };
                    foreach (var c in moviesOnCategory.Categories)
                    {
                        if (c.Id == categoryId)
                        {
                            c.IsActive = true;
                            break;
                        }
                    }
                    if (categoryId > 0)
                    {
                        subs = subs.Where(c => c.Id == categoryId).ToList();
                    }
                    var categoryIds = subs.Select(x => x.Id).ToList();
                    var movies      = await _movieService.SearchMoviesWithAsync(pageSize : pageSize, categoryIds : categoryIds);

                    moviesOnCategory.Movies = movies.Select(x => _movieModelFactory.PrepareMovieModel(x)).ToList();

                    model.Add(moviesOnCategory);
                }
            }
            catch (Exception e)
            {
                throw;
            }
            return(model);
        }
コード例 #5
0
        private async Task <MoviesOnCategoriesModel> LoadMovie(int categoryId = 0,
                                                               int pageIndex  = 1, int pageSize = 12)
        {
            var model = new MoviesOnCategoriesModel();

            try
            {
                var category = _categoryService.GetCategoryById(categoryId);
                model.CategoryName   = category.Name;
                model.CategoryId     = category.Id;
                model.CategorySeName = category.GetSeName();

                var movies = await _movieService.SearchMoviesWithAsync(pageSize : pageSize, categoryIds : new List <int> {
                    categoryId
                });

                model.Movies = movies.ToList().Select(x => _movieModelFactory.PrepareMovieModel(x, 400)).ToList();
            }
            catch (Exception e)
            {
                throw;
            }
            return(model);
        }
コード例 #6
0
ファイル: MovieController.cs プロジェクト: vikhalv/butv
        public IActionResult Details(string sename)
        {
            var urlRecord = _urlRecordService.GetBySlug(sename);

            if (urlRecord == null || urlRecord.EntityName != "MovieItem")
            {
                return(RedirectToAction("Error", "Home"));
            }

            var movie = _movieService.GetMovieById(urlRecord.EntityId);

            if (movie == null)
            {
                return(RedirectToAction("Error", "Home"));
            }

            var model = _movieModelFactory.PrepareMovieModel(movie, 400, true, true);

            model.Description = movie.Description;
            int categoryId = ViewData["categoryId"] != null ? (int)ViewData["categoryId"] : 0;

            if (categoryId == 0)
            {
                var mc = _movieCategoryService.GetMovieCategoriesById(movie.Id);
                if (mc != null)
                {
                    model.CategoryId = categoryId = mc.FirstOrDefault().CategoryId;
                }
                else
                {
                    return(RedirectToAction("Error", "Home"));
                }
            }
            var category = _categoryService.GetCategoryById(categoryId);

            var tagParts = movie.Tags.Split(',');

            foreach (var item in tagParts)
            {
                model.Tags.Add(item.Trim());
                var tagFound = _tagService.GetByName(item.Trim());
                if (tagFound == null)
                {
                    var newTag = new Tags()
                    {
                        Hit  = 0,
                        Name = item.Trim()
                    };
                    _tagService.InsertTags(newTag);
                }
                else
                {
                    tagFound.Hit += 1;
                    _tagService.SaveTags(tagFound);
                }
            }
            var genreParts = movie.Genres.Split(',');

            foreach (var item in genreParts)
            {
                model.Genres.Add(item.Trim());
            }
            var directors = _diretorService.GetDirectorsByMovieId(movie.Id);
            var dirs      = new Dictionary <string, string>();

            foreach (var d in directors)
            {
                if (d != null)
                {
                    dirs.Add(d.Director.Name, d.Director.GetSeName());
                }
            }
            model.Directors = dirs;
            var countries    = new Dictionary <string, string>();
            var countryParts = movie.Country.Split(',');

            foreach (var c in countryParts)
            {
                countries.Add(c, ""); // need to have sename
            }
            model.Countries = countries;

            var sources  = LoadMovieEpisodes(model.Id);
            var gSources = sources.GroupBy(g => g.Source);

            if (model.HasEpisode)
            {
                model.MovieSources = new List <MovieEpisodeModel>();
                int count = 1;
                foreach (var item in gSources)
                {
                    var movieEpisode = new MovieEpisodeModel()
                    {
                        Source   = item.Key,
                        Episodes = item.ToList()
                    };
                    model.MovieSources.Add(movieEpisode);
                }
                foreach (var source in model.MovieSources.OrderBy(o => o.DisplayOrder))
                {
                    source.DisplaySource = "Server " + count++;
                }
                var mvEpisode = model.MovieSources.FirstOrDefault();
                var lastEp    = mvEpisode.Episodes.LastOrDefault();
                lastEp.Default      = true;
                model.PlayingSource = lastEp;
            }
            else
            {
                foreach (var item in gSources)
                {
                    if (item.Count() == 1)
                    {
                        var found = item.FirstOrDefault();
                        found.Default = true;
                    }
                    else
                    {
                        var found = item.FirstOrDefault(f => f.Quality.Contains("HD") && f.Name.Contains("VietSub"));
                        if (found != null)
                        {
                            found.Default = true;                // Vietsub is the top priority.
                        }
                        else
                        {
                            foreach (var s in item)
                            {
                                if (s.Quality.Contains("HD"))
                                {
                                    s.Default = true;
                                    break;
                                }
                            }
                        }
                    }
                    var movieEpisode = new MovieEpisodeModel()
                    {
                        Source   = item.Key,
                        Episodes = item.ToList()
                    };

                    model.MovieSources.Add(movieEpisode);
                }
                int count = 1;
                foreach (var source in model.MovieSources)
                {
                    if (source.Source.Equals(nameof(SourcePriority.bilutv)))
                    {
                        source.DisplayOrder = (int)SourcePriority.bilutv;
                    }

                    if (source.Source.Equals(nameof(SourcePriority.phimmoi)))
                    {
                        source.DisplayOrder = (int)SourcePriority.phimmoi;
                    }

                    if (source.Source.Equals(nameof(SourcePriority.phimbathu)))
                    {
                        source.DisplayOrder = (int)SourcePriority.phimbathu;
                    }
                }
                foreach (var source in model.MovieSources.OrderBy(o => o.DisplayOrder))
                {
                    source.DisplaySource = "Server " + count++;
                }


                model.MovieSources = model.MovieSources.OrderBy(o => o.DisplayOrder).ToList();
                if (model.MovieSources.Any())
                {
                    var episode = model.MovieSources.FirstOrDefault();
                    if (episode != null && episode.Episodes.Any())
                    {
                        model.PlayingSource = model.MovieSources.FirstOrDefault().Episodes.FirstOrDefault(f => f.Default);
                    }
                    else
                    {
                        model.PlayingSource = new SubMovieItemModel();
                    }
                }
            }

            string breadcrumbCacheKey = string.Format(ModelCacheEventConsumer.MOVIE_BREADCRUMB_KEY, movie.Id);

            model.Breadcrumb = _cacheManager.Get(breadcrumbCacheKey, () =>
            {
                var breadcrumbModel = new MovieBreadcrumbModel
                {
                    MovieId     = movie.Id,
                    MovieName   = movie.Name,
                    MovieSeName = movie.GetSeName()
                };
                breadcrumbModel.CategoryBreadcrumb = category.GetCategoryBreadCrumb(_categoryService)
                                                     .Select(catBr => new CategorySimpleModel
                {
                    Id     = catBr.Id,
                    Name   = catBr.Name,
                    SeName = catBr.GetSeName()
                })
                                                     .ToList();
                return(breadcrumbModel);
            });

            movie.View += 1;
            _movieService.SaveMovie(movie);
            return(View(model));
        }