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)); }
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); }