コード例 #1
0
        public async Task <IViewComponentResult> InvokeAsync(CaaS.Content cafeRoot = null)
        {
            var isCollectionPage = true;

            if (cafeRoot == null)
            {
                var productRootPaged = await _contentCache.GetByType(CafeCollection.ContentTypeAlias, "en-US");

                cafeRoot         = productRootPaged.Content.Items.FirstOrDefault();
                isCollectionPage = false;
            }

            if (cafeRoot == null)
            {
                throw new Exception("Product Root is null");
            }

            var cafeCollection = CafeCollection.MapToType(cafeRoot);

            var children = await _contentCache.GetChildren(cafeRoot.Id, "en-US");

            cafeCollection.IsCollectionPage = isCollectionPage;
            cafeCollection.Cafes            = children.Content.Items.Select(c => Cafe.MapToType(c));

            return(View(cafeCollection));
        }
コード例 #2
0
        public static CafeCollection MapToType(CaaS.Content content)
        {
            var model = new CafeCollection
            {
                Title    = content.Value <string>("title"),
                BodyText = content.Value <string>("bodyText"),
            };

            model.MapCommonProperties(content);
            return(model);
        }
コード例 #3
0
        public static ProductCollection MapToType(CaaS.Content content)
        {
            var model = new ProductCollection
            {
                Title    = content.Value <string>("title"),
                SubTitle = content.Value <string>("subTitle"),
            };

            model.MapCommonProperties(content);
            return(model);
        }
コード例 #4
0
        public static ContentPage MapToType(CaaS.Content content)
        {
            var model = new ContentPage
            {
                Title     = content.Value <string>("title"),
                BodyText  = content.Value <UmbracoGrid>("bodyText"),
                HeroImage = content.Value <CaaS.Image>("heroImage"),
            };

            model.MapCommonProperties(content);
            return(model);
        }
コード例 #5
0
 public IRetrievedContent GetTypedContent(CaaS.Content content)
 {
     return(content.ContentTypeAlias switch
     {
         Cafe.ContentTypeAlias => Cafe.MapToType(content),
         CafeCollection.ContentTypeAlias => CafeCollection.MapToType(content),
         ContentPage.ContentTypeAlias => ContentPage.MapToType(content),
         Home.ContentTypeAlias => Home.MapToType(content),
         Product.ContentTypeAlias => Product.MapToType(content),
         ProductCollection.ContentTypeAlias => ProductCollection.MapToType(content),
         _ => throw new TypeLoadException($"Unknown type {content.ContentTypeAlias} encountered.")
     });
コード例 #6
0
        public static Home MapToType(CaaS.Content content)
        {
            var model = new Home
            {
                BannerImage = content.Value <CaaS.Image>("bannerImage"),
                Headline    = content.Value <string>("headline"),
                SubHeading  = content.Value <string>("subHeading"),
                Title       = content.Name,
            };

            model.MapCommonProperties(content);
            return(model);
        }
コード例 #7
0
        public static Product MapToType(CaaS.Content content)
        {
            var model = new Product
            {
                Title        = content.Value <string>("title"),
                Price        = content.Value <decimal>("price"),
                Description  = content.Value <IHtmlContent>("description"),
                ProductImage = content.Value <CaaS.Image>("productImage"),
            };

            model.MapCommonProperties(content);
            return(model);
        }
コード例 #8
0
        public static Cafe MapToType(CaaS.Content content)
        {
            var model = new Cafe
            {
                Title          = content.Name,
                BuildingNumber = content.Value <string>("buildingNumber"),
                AddressLine1   = content.Value <string>("addressLine1"),
                AddressLine2   = content.Value <string>("addressLine2"),
                Suburb         = content.Value <string>("suburb"),
                Postcode       = content.Value <string>("postcode"),
                State          = content.Value <string>("state")
            };

            model.MapCommonProperties(content);
            return(model);
        }
コード例 #9
0
        public IViewComponentResult Invoke(CaaS.Content content)
        {
            var sb = new StringBuilder("<div style=\"display: grid; grid-template-columns: auto 1fr; grid-gap: 20px;\">");

            sb.Append($"<h4>ContentTypeAlias: {content.ContentTypeAlias}</h4>");

            foreach (var property in content.Properties)
            {
                sb.Append("<div>");
                sb.Append(property.Key);
                sb.Append("</div>");
                sb.Append("<div>");
                sb.Append(property.Value);
                sb.Append("</div>");
            }

            sb.Append("</div>");
            return(new HtmlContentViewComponentResult(new HtmlString(sb.ToString())));
        }