Ejemplo n.º 1
0
        public async Task <IActionResult> MyPresentationsByCategory(string categoryName, int?page, int?itemsPerPage)
        {
            var vm = new PresentationsViewModel();

            vm.Title = $"{categoryName.ToUpper()}";
            vm.ButtonsToolbarModel = ButtonsToolbarModel.UserModelwithHighlightedIndex(ButtonsToolbarModel.IndexOf(categoryName));
            vm.NavbarIndexPair     = new LeftNavbar.IndexPair {
                IndexWhenUserAuthorized = NavbarModel.AuthorizableItemsIndex.HomeMyPresentations
            };


            var userId              = _userManager.GetUserId(this.User);
            var pagingOptions       = PagingOptions.CreateWithTheseOrDefaults(page, itemsPerPage);
            var presentationsResult = await _presentationsRepository.UserPresentationsFromCategory(userId, categoryName, pagingOptions);

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

            if (presentationsResult.Value.Count == 0)
            {
                vm.TopMessage     = $"You do not have any presentations in the {categoryName.ToLower()} category.";
                vm.TopMessageHref = $"/{nameof(HomeController).WithoutControllerPart()}/{nameof(HomeController.UploadPresentation)}";
                return(DisplayListPage(vm));
            }

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

            vm.PaginationModel = PaginationViewModel.BuildModelWith(presentationsResult.TotalPages, pagingOptions, i =>
                                                                    $"/{nameof(HomeController).WithoutControllerPart()}/{nameof(HomeController.MyPresentationsByCategory)}?categpryName=" +
                                                                    $"{categoryName}&page={i}&itemsPerPage={pagingOptions.ItemsPerPage}");
            return(DisplayListPage(vm));
        }
Ejemplo n.º 2
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));
        }