Example #1
0
        private static ResourcesPresentationModel PreparePresentationModel(ResourcesPresentationModel model)
        {
            // Ensure that the pagination values are always set.

            if (model == null)
            {
                model = new ResourcesPresentationModel();
            }
            if (model.Pagination == null)
            {
                model.Pagination = new Pagination();
            }
            if (model.Pagination.Page == null)
            {
                model.Pagination.Page = 1;
            }
            if (model.Pagination.Items == null)
            {
                model.Pagination.Items = DefaultItemsPerPage;
            }
            model.ItemsPerPage        = Reference.ItemsPerPage;
            model.DefaultItemsPerPage = DefaultItemsPerPage;

            return(model);
        }
Example #2
0
        private ResourceListModel <TResource> PartialRecentResources <TResource>(ResourcesPresentationModel presentation, Func <Guid, IList <TResource> > getRecentlyViewedResources)
            where TResource : Resource
        {
            presentation = PreparePresentationModel(presentation);
            var user = CurrentUser;

            // Get the resources.

            var model = GetRecentlyViewedResources(user.Id, presentation, getRecentlyViewedResources);

            // Set the data for all resources in the model.

            return(GetPartialResourceListModel(user, model));
        }
Example #3
0
 public ActionResult CategoryVideos(ResourceSearchCriteria criteria, ResourcesPresentationModel presentation)
 {
     return(Videos(criteria, presentation));
 }
Example #4
0
 public ActionResult QnAs(ResourceSearchCriteria criteria, ResourcesPresentationModel presentation)
 {
     return(View("QnAs", Resources(criteria, presentation, i => _resourcesQuery.GetQnAs(i), u => _resourcesQuery.GetRecentlyViewedQnAs(u, RecentItemsCount))));
 }
Example #5
0
        private ResourceListModel <TResource> GetRecentlyViewedResources <TResource>(Guid userId, ResourcesPresentationModel presentation, Func <Guid, IList <TResource> > getRecentlyViewedResources)
            where TResource : Resource
        {
            var results = getRecentlyViewedResources(userId);

            return(new ResourceListModel <TResource>
            {
                Categories = _resourcesQuery.GetCategories(),
                Presentation = presentation,
                Criteria = new ResourceSearchCriteria {
                    ResourceType = GetResourceType <TResource>()
                },
                Results = new ResourceListResultsModel <TResource>
                {
                    ResourceIds = results.Select(r => r.Id).ToList(),
                    Resources = results.ToDictionary(r => r.Id, r => r),
                },
            });
        }
Example #6
0
        private ResourceListModel <TResource> Search <TResource>(Guid userId, ResourceSearchCriteria criteria, ResourcesPresentationModel presentation, IList <Category> categories, Func <IList <Guid>, IList <TResource> > getResources, Func <Guid, IList <TResource> > getRecentlyViewedResources)
            where TResource : Resource
        {
            // Search.

            var execution = _executeResourceSearchCommand.Search(criteria, presentation.Pagination.ToRange());

            return(new ResourceListModel <TResource>
            {
                Categories = categories,
                Presentation = presentation,
                Criteria = execution.Criteria,
                TotalResources = execution.Results.ResourceTypeHits.ToDictionary(h => h.Key, h => h.Value),
                Results = new ResourceListResultsModel <TResource>
                {
                    ResourceIds = execution.Results.ResourceIds,
                    Resources = getResources(execution.Results.ResourceIds).ToDictionary(r => r.Id, r => r),
                },
                RecentItems = getRecentlyViewedResources(userId).Cast <Resource>().ToList(),
            });
        }
Example #7
0
        private ResourceListModel <TResource> PartialResources <TResource>(ResourceSearchCriteria criteria, ResourcesPresentationModel presentation, Func <IList <Guid>, IList <TResource> > getResources, Func <Guid, IList <TResource> > getRecentlyViewedResources)
            where TResource : Resource
        {
            // Save the current search.

            criteria.ResourceType = GetResourceType <TResource>();
            criteria.SortCriteria = new ResourceSearchSortCriteria {
                SortOrder = ResourceSortOrder.CreatedTime, ReverseSortOrder = false
            };
            presentation = PreparePresentationModel(presentation);
            MemberContext.CurrentResourcesSearch = new ResourcesSearchNavigation(criteria, presentation);

            // Search.

            var user       = CurrentUser;
            var categories = _resourcesQuery.GetCategories();
            var model      = Search(user.Id, criteria, presentation, categories, getResources, getRecentlyViewedResources);

            // Set the data for all resources in the model.

            return(GetPartialResourceListModel(user, model));
        }
Example #8
0
 public ActionResult PartialRecentQnAs(ResourcesPresentationModel presentation)
 {
     return(PartialView(PartialRecentResources(presentation, u => _resourcesQuery.GetRecentlyViewedQnAs(u, RecentItemsCount))));
 }
Example #9
0
 public ActionResult PartialVideos(ResourceSearchCriteria criteria, ResourcesPresentationModel presentation)
 {
     return(PartialView("PartialVideos", PartialResources(criteria, presentation, i => _resourcesQuery.GetVideos(i), u => _resourcesQuery.GetRecentlyViewedVideos(u, RecentItemsCount))));
 }