Exemple #1
0
        public virtual object Apply(IPublishedElement element, UmbracoMappingContext context)
        {
            var item = element.ToElement <M>();

            var output = mapper.Map <V>(item, context.Items);

            return(output);
        }
        public vmBlock_DataLink Convert(Link link, UmbracoMappingContext context)
        {
            if (link != null)
            {
                if (link.Type == LinkType.External)
                {
                    return(new vmBlock_DataLink()
                    {
                        Title = link.Name,
                        Label = link.Name,
                        Href = link.Url,
                        IsExternalLink = true,
                        IsNewTab = link.Target == "_blank"
                    });
                }
                else
                {
                    var id = link.Udi as GuidUdi;
                    if (id != null)
                    {
                        var content = contentQuery.Content(id);

                        if (content != null)
                        {
                            var name = string.IsNullOrEmpty(link.Name) ? content.Name : link.Name;
                            var udi  = context.Model != null ? new GuidUdi("document", context.Model.Key) : null;

                            var d = new vmBlock_DataLink()
                            {
                                Title    = name,
                                Label    = name,
                                Href     = link.Url,
                                IsActive = link.Udi == udi,
                                IsNewTab = link.Target == "_blank"
                            };
                            return(d);
                        }

                        var media = contentQuery.Media(id);

                        if (media != null)
                        {
                            var name = string.IsNullOrEmpty(link.Name) ? media.Name : link.Name;

                            var d = new vmBlock_DataLink()
                            {
                                Title    = name,
                                Label    = name,
                                Href     = media.Url(),
                                IsNewTab = link.Target == "_blank"
                            };
                            return(d);
                        }
                    }
                }
            }
            return(null);
        }
Exemple #3
0
        public override T From <T>(IDictionary <string, object> items)
        {
            var output = new UmbracoMappingContext();

            AddDefaults(output, items);

            if (items.ContainsKey("Model"))
            {
                output.Model = items["Model"] as IPublishedContent;
            }

            return(output as T);
        }
Exemple #4
0
 public vmBlock_DataImage Convert(IPublishedContent source, UmbracoMappingContext context)
 {
     if (source != null && source.ContentType != null)
     {
         if (source.ContentType.Alias == "Image")
         {
             return(CreateImage(source));
         }
         if (source.ContentType.Alias == "File")
         {
             return(CreateFile(source));
         }
     }
     return(new vmBlock_DataImage());
 }
 public vmBlock_DataLink Convert(IPublishedContent link, UmbracoMappingContext context)
 {
     if (link != null)
     {
         return(new vmBlock_DataLink()
         {
             Title = link.Name,
             Label = link.Name,
             Href = link.Url,
             IsActive = link == context.Model
         });
     }
     else
     {
         return(null);
     }
 }
        public object Convert(IEnumerable <IPublishedElement> elements, UmbracoMappingContext context)
        {
            if (elements.Any())
            {
                var element = elements.FirstOrDefault();

                foreach (var i in defaultItems)
                {
                    if (i.IsValid(element))
                    {
                        return(i.Apply(element, context));
                    }
                }
                return(null);
            }
            else
            {
                return(null);
            }
        }
        public IEnumerable <object> Convert(IEnumerable <IPublishedElement> elements, UmbracoMappingContext context)
        {
            var output = new List <object>();

            if (elements.Any())
            {
                var element = elements.FirstOrDefault();

                foreach (var i in defaultItems)
                {
                    if (i.IsValid(element))
                    {
                        output.Add(i.Apply(element, context));
                    }
                }
            }

            return(output);
        }
Exemple #8
0
        public object Resolve(Source source, Dest destination, IPublishedContent sourceMember, string destPropertyName, UmbracoMappingContext context)
        {
            var cmsModel  = config.CMSModels.Where(c => c.Name == sourceMember.ContentType.Alias.FirstCharacterToUpper()).FirstOrDefault();
            var viewmodel = config.ViewModels.Where(x => x.Name == $"{YuzuConstants.Configuration.BlockPrefix}{cmsModel.Name}" || x.Name == $"{YuzuConstants.Configuration.PagePrefix}{cmsModel.Name}").FirstOrDefault();

            return(mapper.Map(sourceMember, cmsModel, viewmodel, context.Items));
        }