Example #1
0
        public ActionResult CreateTv(TvViewModel tvViewModel, HttpPostedFileBase uploadImage)
        {
            try
            {
                if (ModelState.IsValid && uploadImage != null)
                {
                    byte[] imageData = null;

                    using (var binaryReader = new BinaryReader(uploadImage.InputStream))
                    {
                        imageData = binaryReader.ReadBytes(uploadImage.ContentLength);
                    }

                    TvDto tvDto = MappingTvViewModelToTvDto(tvViewModel);
                    tvDto.Image = imageData;
                    int tvId = tvService.Create(tvDto);

                    return(RedirectToAction("CreateTvSuccess", new { tvId }));
                }
                return(View(tvViewModel));
            }
            catch (ValidationException ex)
            {
                return(Content(ex.Message));
            }
        }
Example #2
0
        private TvDto MappingTvViewModelToTvDto(TvViewModel tvViewModel)
        {
            var mapper = new MapperConfiguration(cfg => cfg.CreateMap <TvViewModel, TvDto>()).CreateMapper();
            var tvDto  = mapper.Map <TvViewModel, TvDto>(tvViewModel);

            return(tvDto);
        }
Example #3
0
        public ActionResult EditTv(TvViewModel tvViewModel, HttpPostedFileBase uploadImage)
        {
            try
            {
                TvDto tvDto = MappingTvViewModelToTvDto(tvViewModel);

                if (uploadImage != null)
                {
                    byte[] imageData = null;

                    using (var binaryReader = new BinaryReader(uploadImage.InputStream))
                    {
                        imageData = binaryReader.ReadBytes(uploadImage.ContentLength);
                    }
                    tvDto.Image = imageData;
                }
                else
                {
                    tvDto.Image = null;
                }


                tvService.Update(tvDto);

                TvDto tvDtoUpdated = tvService.GetTv(tvDto.Id);

                var tvViewModelUpdated = MappingTvDtoToTvViewModel(tvDtoUpdated);
                return(View("CreateTvSuccess", tvViewModelUpdated));
            }
            catch (ValidationException ex)
            {
                return(Content(ex.Message));
            }
        }
Example #4
0
        /// <summary>
        /// Get all tv series lists
        /// </summary>
        /// <returns>TvViewModel</returns>
        public ActionResult Index()
        {
            TvViewModel model = new TvViewModel();

            model.GetLatest      = _tvApi.GetLatest();
            model.GetPopulor     = _tvApi.GetPopulor();
            model.GetTopRated    = _tvApi.GetTopRated();
            model.GetAiringToday = _tvApi.GetAiringToday();

            return(View(model));
        }
        private ListPageConfig GetListPageConfig(BaseItemDto item, ViewType context)
        {
            var config = new ListPageConfig();

            if (context == ViewType.Tv)
            {
                TvViewModel.SetDefaults(config);

                if (item.IsType("season"))
                {
                    config.DefaultViewType = ListViewTypes.List;
                }
            }
            else if (context == ViewType.Movies)
            {
                MoviesViewModel.SetDefaults(config);
            }
            else if (context == ViewType.Games)
            {
                GamesViewModel.SetDefaults(config, item.GameSystem);
            }

            return(config);
        }
Example #6
0
        private ListPageConfig GetListPageConfig(BaseItemDto item, ViewType context)
        {
            var config = new ListPageConfig();

            if (context == ViewType.Tv || item.IsType("season"))
            {
                TvViewModel.SetDefaults(config);

                if (item.IsType("season"))
                {
                    config.DefaultViewType = ListViewTypes.List;

                    config.PosterImageWidth      = 480;
                    config.PosterStripImageWidth = 592;
                    config.ThumbImageWidth       = 592;
                }
            }
            else if (context == ViewType.Movies)
            {
                MoviesViewModel.SetDefaults(config);
            }
            else if (context == ViewType.Games)
            {
                GamesViewModel.SetDefaults(config, item.GameSystem);
            }

            if (item.IsFolder)
            {
                config.CustomItemQuery = (vm, displayPreferences) =>
                {
                    if (item.IsType("series"))
                    {
                        return(_apiClient.GetSeasonsAsync(new SeasonQuery
                        {
                            UserId = _sessionManager.CurrentUser.Id,
                            SeriesId = item.Id,
                            Fields = FolderPage.QueryFields
                        }, CancellationToken.None));
                    }


                    if (item.IsType("season"))
                    {
                        return(_apiClient.GetEpisodesAsync(new EpisodeQuery
                        {
                            UserId = _sessionManager.CurrentUser.Id,
                            SeriesId = item.SeriesId,
                            SeasonId = item.Id,
                            Fields = FolderPage.QueryFields
                        }, CancellationToken.None));
                    }

                    var query = new ItemQuery
                    {
                        UserId = _sessionManager.CurrentUser.Id,

                        ParentId = item.Id,

                        Fields = FolderPage.QueryFields
                    };

                    // Server will sort boxset titles based on server settings
                    if (!item.IsType("boxset"))
                    {
                        query.SortBy    = new[] { ItemSortBy.SortName };
                        query.SortOrder = displayPreferences.SortOrder;
                    }

                    return(_apiClient.GetItemsAsync(query, CancellationToken.None));
                };

                if (item.IsType("season") && item.IndexNumber.HasValue && item.IndexNumber.Value > 0)
                {
                    config.DisplayNameGenerator = FolderPage.GetDisplayNameWithAiredSpecial;
                }
            }

            return(config);
        }