Ejemplo n.º 1
0
        public List <GroupedContentModel> Map(List <ServiceLineMappingResponse> source)
        {
            List <GroupedContentModel> groupedResponse = new List <GroupedContentModel>();
            var groupedMapping = source.GroupBy(c => c.MappingType);

            foreach (var group in groupedMapping)
            {
                TextInfo textInfo = new CultureInfo("en-US", false).TextInfo;

                GroupedContentModel model = new GroupedContentModel();
                model.Title = "Client Mapping Demo: " + textInfo.ToTitleCase(group.Key);
                model.Slug  = group.Key;

                //Add only a distinct set of mapped services.  It is possible to get multiple hits depending on how
                //the mapping was originally done.

                List <ServiceLineMappingResponse> subMappings     = group.GroupBy(c => c.Name).Select(grp => grp.First()).ToList();
                List <ContentReferenceModel>      referenceModels = new List <ContentReferenceModel>();
                foreach (ServiceLineMappingResponse response in subMappings)
                {
                    referenceModels.Add(new ContentReferenceModel
                    {
                        Title = response.Name,
                        Uri   = response.Uri,
                        Type  = response.MappingType
                    });
                }
                model.Items = referenceModels;
                groupedResponse.Add(model);
            }

            return(groupedResponse);
        }
Ejemplo n.º 2
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));
        }
Ejemplo n.º 3
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);
        }