示例#1
0
            public List <BannerBlockItemViewModel> Resolve(BlockModel block, BannersBlockViewModel bannersViewModel, List <BannerBlockItemViewModel> destMember, ResolutionContext context)
            {
                var result        = new List <BannerBlockItemViewModel>();
                var blockTemplate = _fieldTemplateService.Get <FieldTemplateBase>(block.FieldTemplateSystemId);

                if (blockTemplate.FieldGroups.Any(x => x.Id == "Banners"))
                {
                    var banners = block.GetValue <IList <MultiFieldItem> >(BlockFieldNameConstants.Banners);
                    if (banners != null)
                    {
                        result.AddRange(banners.Select(c => c.MapTo <BannerBlockItemViewModel>()));
                    }
                }
                else if (blockTemplate.FieldGroups.Any(x => x.Id == "Banner"))
                {
                    var image  = block.GetValue <Guid>(BlockFieldNameConstants.BlockImagePointer).MapTo <ImageModel>();
                    var banner = new BannerBlockItemViewModel()
                    {
                        LinkText   = block.GetValue <string>(BlockFieldNameConstants.LinkText),
                        ActionText = block.GetValue <string>(BlockFieldNameConstants.ActionText),
                        Image      = image,
                        ImageUrl   = image.GetUrlToImage(new System.Drawing.Size(786, -1), new System.Drawing.Size(1314, -1)).Url,
                        LinkUrl    = GetBannerUrl(block)
                    };
                    result.Add(banner);
                }

                return(result);
            }
示例#2
0
            public List <BannerBlockItemViewModel> Resolve(BlockModel block, BannersBlockViewModel bannersViewModel, List <BannerBlockItemViewModel> destMember, ResolutionContext context)
            {
                var result        = new List <BannerBlockItemViewModel>();
                var blockTemplate = _fieldTemplateService.Get <FieldTemplateBase>(block.FieldTemplateSystemId);

                if (blockTemplate.FieldGroups.Any(x => x.Id == "Banners"))
                {
                    var banners = block.GetValue <IList <MultiFieldItem> >(BlockFieldNameConstants.Banners);
                    if (banners != null)
                    {
                        result.AddRange(banners.Select(c => c.MapTo <BannerBlockItemViewModel>()));
                    }
                }
                else if (blockTemplate.FieldGroups.Any(x => x.Id == "Banner"))
                {
                    var linkToPage = block.GetValue <PointerPageItem>(BlockFieldNameConstants.Link)?.MapTo <LinkModel>();
                    var banner     = new BannerBlockItemViewModel()
                    {
                        ActionText = block.GetValue <string>(BlockFieldNameConstants.BlockText),
                        Image      = block.GetValue <Guid>(BlockFieldNameConstants.BlockImagePointer).MapTo <ImageModel>(),
                        LinkUrl    = !string.IsNullOrEmpty(linkToPage?.Href) ? linkToPage.Href : ""
                    };
                    result.Add(banner);
                }

                return(result);
            }