Exemplo n.º 1
0
        public ActionResult VideosByTopic()
        {
            //Try to get the slug objects
            object categorySlug = ControllerContext.RouteData.Values["categorySlug"];

            if (categorySlug == null)
            {
                return(HttpNotFound("Sorry, the content was not found."));
            }
            string categorySlugValue = categorySlug.ToString();

            if (string.IsNullOrEmpty(categorySlugValue))
            {
                return(HttpNotFound("Sorry, the content was not found."));
            }

            //Select the appropriate category
            ContentCategoryList categoryList = ContentCategoryFactory.GetVideoLibraryCategories();
            Category            category     = categoryList.Categories.Find(c => c.Slug == categorySlugValue);

            //Create the query
            string query = GetQueryStringFromServiceLines(category);

            ContentList videos = _client.Content.SearchContent(new ContentSearchRequest
            {
                Count   = DEFAULT_COUNT,
                Buckets = new List <string> {
                    "videos-v2"
                },
                Languages = new List <string> {
                    "en"
                },
                Query = query
            });

            //Convert to the view model.
            GroupedContentModel model = new GroupedContentModel();

            model.Title = category.Names.Find(c => c.LanguageCode == "en").Value;
            model.Slug  = category.Slug;

            ContentReferenceModelMapper mapper = new ContentReferenceModelMapper();

            foreach (var item in videos.Items)
            {
                model.Items.Add(mapper.Map(item));
            }

            return(View(model));
        }
Exemplo n.º 2
0
        public GroupedContentModel Get(string category, int skip = 0, int top = 4)
        {
            GroupedContentModel groupedContent = new GroupedContentModel();

            ContentCategoryList categoryList = ContentCategoryFactory.GetVideoLibraryCategories();

            ContentReferenceModelMapper mapper = new ContentReferenceModelMapper();
            Category mappedCategory            = categoryList.Categories.Find(c => c.Slug.Equals(category, StringComparison.InvariantCultureIgnoreCase));

            //Create the query
            string query = GetQueryStringFromServiceLines(mappedCategory);

            //Execute the query
            ContentList videos = _client.Content.SearchContent(new ContentSearchRequest
            {
                Count   = top,
                Offset  = skip,
                Buckets = new List <string> {
                    "videos-v2"
                },
                Languages = new List <string> {
                    "en"
                },
                Query = query
            });

            //Create the model
            if (videos.Items.Count > 0)
            {
                groupedContent = new GroupedContentModel
                {
                    Slug  = mappedCategory.Slug,
                    Title = mappedCategory.Names.Find(c => c.LanguageCode == "en").Value,
                    Total = videos.Total
                };

                foreach (var video in videos.Items)
                {
                    groupedContent.Items.Add(mapper.Map(video));
                }
            }

            return(groupedContent);
        }
Exemplo n.º 3
0
        public List <GroupedContentModel> Map(List <ContentResponse> source)
        {
            List <GroupedContentModel> groupedRelatedContent = new List <GroupedContentModel>();

            //Request the bucket to category configuration so that we know how to create the groups.
            ContentCategoryList categoryList = ContentCategoryFactory.GetRelatedServicesCategories();

            foreach (Category category in categoryList.Categories)
            {
                //Initilize the list the collection of content within the specific group.  Add
                //all content from "relatedContent" that match the bucket associated with the category.
                List <ContentResponse> groupedContent = new List <ContentResponse>();
                foreach (Bucket bucket in category.Buckets)
                {
                    groupedContent.AddRange(source.FindAll(c => c.Bucket.Slug == bucket.Slug));
                }

                if (groupedContent.Count > 0)
                {
                    List <ContentReferenceModel> contentList = new List <ContentReferenceModel>();
                    foreach (var item in groupedContent)
                    {
                        ContentReferenceModelMapper mapper = new ContentReferenceModelMapper();
                        contentList.Add(mapper.Map(item));
                    }

                    groupedRelatedContent.Add(new GroupedContentModel
                    {
                        Title = category.Names.Find(c => c.LanguageCode == "en").Value,
                        Slug  = category.Slug,
                        Items = contentList
                    });
                }
            }

            return(groupedRelatedContent);
        }