public async Task <IActionResult> MyPresentations(int?page, int?itemsPerPage)
        {
            var vm = new PresentationsViewModel();

            vm.NavbarIndexPair = new LeftNavbar.IndexPair
            {
                IndexWhenUserAuthorized = NavbarModel.AuthorizableItemsIndex.HomeMyPresentations
            };
            var pagingOptions = PagingOptions.CreateWithTheseOrDefaults(page, itemsPerPage);

            var userPresentationsResult = await _presentationsRepository.GetPresentationsForUser(_userManager.GetUserId(User),
                                                                                                 pagingOptions);

            if (userPresentationsResult.ErrorMessageIfAny != null)
            {
                vm.ErrorMessage = userPresentationsResult.ErrorMessageIfAny;
                return(base.DisplayListPage(vm));
            }
            if (userPresentationsResult.Value.Count == 0)
            {
                vm.TopMessage     = "You do not have any presentations. Start uploading some";
                vm.TopMessageHref = $"/{nameof(HomeController).WithoutControllerPart()}/{nameof(HomeController.UploadPresentation)}";
                return(base.DisplayListPage(vm));
            }

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

            vm.PaginationModel = PaginationViewModel.BuildModelWith(userPresentationsResult.TotalPages,
                                                                    pagingOptions, index => $"/{nameof(HomeController).WithoutControllerPart()}/" +
                                                                    $"{nameof(HomeController.MyPresentations)}?page=" + index + "&itemsPerPage=" + pagingOptions.ItemsPerPage);

            vm.TopMessage          = "My presentations";
            vm.ButtonsToolbarModel = ButtonsToolbarModel.UserModelwithHighlightedIndex(0);
            return(base.DisplayListPage(vm));
        }
        public async Task <IActionResult> UserPresentationsByTag(string tag, int?page, int?itemsPerPage)
        {
            var vm = new PresentationsViewModel();

            vm.NavbarIndexPair = defaultNavbarIndexPair;

            if (tag == null || tag.Length == 0)
            {
                vm.ErrorMessage = "You have not provided any tag to search for.";
                return(base.DisplayListPage(vm));
            }

            var pagingOptions = PagingOptions.CreateWithTheseOrDefaults(page, itemsPerPage);
            var id            = _userManager.GetUserId(User);
            var presentations = await _presentationsRepository.GetUserPresentationsFromTag(tag, id, pagingOptions);

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

            if (presentations.Value.Count == 0)
            {
                vm.TopMessage = "There are no presentations containing the tag \"" + tag + "\"";
                return(base.DisplayListPage(vm));
            }

            vm.TopMessage    = $"Presentations associated with \"{tag}\", page {pagingOptions.PageIndex} of {presentations.TotalPages}";
            vm.Presentations = await base.CreateCardsModel(presentations.Value);

            vm.PaginationModel = await CreateTagPaginationModel(tag, pagingOptions, presentations.TotalPages);

            return(base.DisplayListPage(vm));
        }
示例#3
0
        public async Task <IActionResult> GetUsersForPresentation(int presentationId, int?page, int?itemsPerPage)
        {
            var pagingOptions = PagingOptions.CreateWithTheseOrDefaults(page, itemsPerPage);
            var usersResult   = await _usersRepository.GetUsersForPresentation(presentationId, pagingOptions);

            if (usersResult.ErrorMessageIfAny != null)
            {
                return(new JsonResult(new { errorMessage = usersResult.ErrorMessageIfAny }));
            }
            var usersList = usersResult.Value.Select(u => new { id = u.Id, name = u.Name });

            return(new JsonResult(usersList));
        }
        public async Task <IActionResult> SearchPublicPresentations(string keywords, string where, int?page, int?itemsPerPage)
        {
            var vm = new PresentationsViewModel();

            vm.NavbarIndexPair = defaultNavbarIndexPair;

            if (keywords == null || keywords.Length == 0)
            {
                vm.TopMessage = "You provided no keywords to search with";
                return(base.DisplayListPage(vm));
            }

            string excludeUserId = null;

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

            _userManager.GetUserId(User);
            var pagingOptions = PagingOptions.CreateWithTheseOrDefaults(page, itemsPerPage);
            var searchType    = CreateSearchType(where);
            var keywordsList  = CreateKeywordsList(keywords);

            PagedOperationResult <List <Presentation> > presentations = await _presentationsRepository.
                                                                        SearchPublicPresentations(keywordsList, pagingOptions, searchType, excludeUserId);

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

            if (presentations.Value.Count == 0)
            {
                vm.TopMessage = "The search returned no results for the keywords " + keywords;
                return(base.DisplayListPage(vm));
            }


            vm.TopMessage    = $"Search results for the keywords \"{keywords}\" in public presentations";
            vm.Presentations = await base.CreateCardsModel(presentations.Value);

            vm.PaginationModel = await CreateSearchPaginationModel(keywordsList, searchType, presentations.TotalPages, pagingOptions);

            return(DisplayPublicListPage(vm));
        }
        public async Task <IActionResult> PublicPresentationsForUser(string userId, int?page, int?itemsPerPage)
        {
            string excludedUserId = null;

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

            var pagingOptions = PagingOptions.CreateWithTheseOrDefaults(page, itemsPerPage);
            var vm            = new PresentationsViewModel();

            vm.NavbarIndexPair = defaultNavbarIndexPair;



            var result = await _presentationsRepository.PublicPresentationsForUser(userId, pagingOptions, excludedUserId);

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

            if (result.Value.Count == 0)
            {
                vm.TopMessage = "There are no public presentations from this user";
                return(base.DisplayListPage(vm));
            }

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

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

            var usersResult = await _usersRepository.GetUserWithId(userId);

            if (usersResult.Value != null)
            {
                vm.TopMessage = $"Page {pagingOptions.PageIndex} of public presentations for {usersResult.Value.Name}";
            }
            return(base.DisplayPublicListPage(vm));
        }
        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));
        }
        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));
        }
        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));
        }
示例#9
0
        public async Task <List <PresentationCardModel> > CreateCardsModel(List <Presentation> presentationsList)
        {
            var presentations = new List <PresentationCardModel>();

            foreach (var item in presentationsList)
            {
                var tagsResult = await _tagsRepository.GetTagsForPresentation(item);

                var categoryResult = await _categoriesRepository.GetCategoryForPresentation(item);

                var usersResult = await _usersRepository.GetUsersForPresentation(item.Id, PagingOptions.CreateWithTheseOrDefaults(1, 10));

                var usersList = new List <PresentationCardModel.UserInfo>();

                if (usersResult.Value != null)
                {
                    usersList = usersResult.Value.Select(u => new PresentationCardModel.UserInfo {
                        Name = u.Name, Href
                             = $"/{nameof(ExploreController).WithoutControllerPart()}/{nameof(ExploreController.PublicPresentationsForUser)}" +
                              $"?userId={u.Id}&page=1&itemsPerPage=10"
                    }).ToList();
                }

                var thumbnail = await _thumbnailRepository.GetThumbnailURLFor(item.FileID);

                presentations.Add(new PresentationCardModel()
                {
                    UserInfos    = usersList,
                    Category     = categoryResult.Value,
                    Presentation = item,
                    ThumbnailURL = thumbnail.Value,
                    Tags         = tagsResult.Value.Select(t => t.Name).ToList()
                });
            }

            return(presentations);
        }