public QueryResultModel PostTemplateQuery(QueryModel model)
        {
            var queryExpression = new StringBuilder();
            IEnumerable <IPublishedContent> contents;

            if (model == null)
            {
                contents = _publishedContentQuery.ContentAtRoot().FirstOrDefault().Children(_variationContextAccessor);
                queryExpression.Append("Umbraco.ContentAtRoot().FirstOrDefault().Children()");
            }
            else
            {
                contents = PostTemplateValue(model, queryExpression);
            }

            // timing should be fairly correct, due to the fact that all the linq statements are yield returned.
            var timer = new Stopwatch();

            timer.Start();
            var results = contents.ToList();

            timer.Stop();

            return(new QueryResultModel
            {
                QueryExpression = queryExpression.ToString(),
                ResultCount = results.Count,
                ExecutionTime = timer.ElapsedMilliseconds,
                SampleResults = results.Take(20).Select(x => new TemplateQueryResult
                {
                    Icon = "icon-document",
                    Name = x.Name
                })
            });
        }
Exemplo n.º 2
0
        public SpeakersApiModel GetSpeakers()
        {
            var speakersNode = _content.ContentAtRoot().OfType <Speakers>().FirstOrDefault();
            var speakers     = new SpeakersApiModel();
            var speakerList  = new List <SpeakerApiModel>();

            if (speakersNode != null)
            {
                //ToDo: Use UmbarcoMapper here?
                foreach (var speaker in speakersNode.Children.OfType <Speaker>().OrderBy(s => s.Name))
                {
                    var image = speaker.Picture == null ? null : _content.Media(speaker.Picture.Id) as Image;                    // ToDo: is this the right way to cast a media type? Wasn't there a more elegant way like TypeMedia?
                    speakerList.Add(new SpeakerApiModel()
                    {
                        Name        = speaker.Name,
                        Description = speaker.ShortDescription,
                        JobJobTitle = speaker.JobTitle,
                        Company     = speaker.Company,
                        PictureUrl  = image?.UmbracoFile.Src
                    });
                }
                speakers.Name        = speakersNode.Name;
                speakers.Description = speakersNode.Description;
                speakers.Speakers    = speakerList;
            }

            return(speakers);
        }
        public List <vmBlock_DataLink> Resolve(Home source, UmbracoMappingContext context)
        {
            var root  = contentQuery.ContentAtRoot().FirstOrDefault();
            var items = root.DescendantsOrSelf().Where(x => x.Level < 3);

            return(mapper.Map <List <vmBlock_DataLink> >(items));
        }
Exemplo n.º 4
0
        public List <vmSub_SiteNavNavSection> Resolve(Home source, UmbracoMappingContext context)
        {
            var root = contentQuery.ContentAtRoot().FirstOrDefault();

            return(root.Children.Where(x => x.TemplateId > 0).Select(x => new vmSub_SiteNavNavSection()
            {
                IsActive = x.Id == context.Model.Id,
                Link = mapper.Map <vmBlock_DataLink>(x),
                SubLinks = mapper.Map <List <vmBlock_DataLink> >(x.Children)
            }).ToList());
        }