Exemplo n.º 1
0
        public async Task <IActionResult> PublicPresentationsByCategory(string categoryName, int?page, int?itemsPerPage)
        {
            string excludedUserId = null;

            if (this.User != null && this.User.Identity.IsAuthenticated)
            {
                excludedUserId = _userManager.GetUserId(this.User);
            }

            var vm = new PresentationsViewModel();

            vm.NavbarIndexPair     = defaultNavbarIndexPair;
            vm.Title               = categoryName.ToUpper();
            vm.ButtonsToolbarModel = ButtonsToolbarModel.PublicModelWithHighlightedIndex(ButtonsToolbarModel.IndexOf(categoryName));

            var pagingOptions       = PagingOptions.CreateWithTheseOrDefaults(page, itemsPerPage);
            var presentationsResult = await _presentationsRepository.PublicPresentationsFromCategory(categoryName, pagingOptions,
                                                                                                     excludedUserId);

            if (presentationsResult.ErrorMessageIfAny != null)
            {
                vm.ErrorMessage = presentationsResult.ErrorMessageIfAny;
                return(DisplayPublicListPage(vm));
            }

            if (presentationsResult.Value.Count == 0)
            {
                vm.TopMessage     = $"There is no public presentation under the category {categoryName}. Be the first to upload one!";
                vm.TopMessageHref = $"/{nameof(HomeController).WithoutControllerPart()}/{nameof(HomeController.UploadPresentation)}";
                return(DisplayPublicListPage(vm));
            }

            vm.PaginationModel = PaginationViewModel.BuildModelWith(presentationsResult.TotalPages, pagingOptions, i =>
                                                                    $"{nameof(ExploreController).WithoutControllerPart()}/{nameof(ExploreController.PublicPresentationsByCategory)}" +
                                                                    $"?categoryName={categoryName}&page={i}&itemsPerPage={pagingOptions.ItemsPerPage}");

            vm.TopMessage    = $"Public presentations in the {categoryName} category, page {pagingOptions.PageIndex} of {presentationsResult.TotalPages}";
            vm.Presentations = await CreateCardsModel(presentationsResult.Value);

            return(DisplayPublicListPage(vm));
        }
Exemplo n.º 2
0
        public async Task <IActionResult> PublicPresentations(int?page, int?itemsPerPage)
        {
            var pagingOptions = PagingOptions.CreateWithTheseOrDefaults(page, itemsPerPage);
            var vm            = new PresentationsViewModel();

            vm.NavbarIndexPair = defaultNavbarIndexPair;

            string excludedUserId = null;

            if (this.User != null)
            {
                excludedUserId = _userManager.GetUserId(this.User);
            }
            var presentations = await _presentationsRepository.PublicPresentations(pagingOptions, excludedUserId);

            if (presentations.ErrorMessageIfAny != null)
            {
                vm.ErrorMessage = presentations.ErrorMessageIfAny;
                return(base.DisplayListPage(vm));
            }

            if (presentations.Value.Count == 0)
            {
                vm.TopMessage     = "There are no other public presentations. Click here to view your own public presentations";
                vm.TopMessageHref = "/" + nameof(HomeController).WithoutControllerPart() + "/" + nameof(HomeController.MyPresentations);
                return(base.DisplayListPage(vm));
            }

            vm.PaginationModel = PaginationViewModel.BuildModelWith(presentations.TotalPages, pagingOptions,
                                                                    index => "/" + nameof(ExploreController).WithoutControllerPart() + "/" + nameof(ExploreController.PublicPresentations) +
                                                                    "?page=" + index + "&itemsPerPage=" + pagingOptions.ItemsPerPage);

            vm.Presentations = await base.CreateCardsModel(presentations.Value);

            vm.Title      = "Public Presentations";
            vm.TopMessage = $"Displaying public presentations, {(presentations.TotalPages > 0 ? presentations.TotalPages : 1)} pages in total";

            vm.ButtonsToolbarModel = ButtonsToolbarModel.PublicModelWithHighlightedIndex(0);

            return(DisplayPublicListPage(vm));
        }