Advertisement
Guest User

Contentstack Sample Entry Model

a guest
Jul 21st, 2020
136
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.35 KB | None | 0 0
  1. namespace csclt
  2. {
  3.     using System;
  4.     using System.Collections.Generic;
  5.  
  6.     using Newtonsoft.Json;
  7.  
  8.     using Contentstack.Core;
  9.     using Contentstack.Core.Configuration;
  10.     using Contentstack.Core.Models;
  11.  
  12.     public class Program
  13.     {
  14.         public class AssetMetadata
  15.         {
  16.             public string Url { get; set; }
  17.         }
  18.        
  19.         public class FieldTypesEntry
  20.         {
  21.             public List<string> StringField { get; set; }
  22.  
  23.             [JsonProperty(propertyName: "datefield")]
  24.             public List<DateTime> DateTimeField { get; set; }
  25.            
  26.             public List<string> RichTextField { get; set; }
  27.  
  28.            
  29.             [JsonProperty(propertyName: "asssetfield")]
  30.             public List<AssetMetadata> AssetField { get; set; }
  31.            
  32.             [JsonProperty(propertyName: "numberfiel")]
  33.             public List<double?> NumberField { get; set; }
  34.  
  35.             public void Render()
  36.             {
  37.                 Console.WriteLine(GetType());
  38.  
  39.                 foreach (double? number in NumberField)
  40.                 {
  41.                     Console.WriteLine("NumberField: " + number);
  42.                 }
  43.                
  44.                 foreach (string value in StringField)
  45.                 {
  46.                     Console.WriteLine("StringField: " + value);
  47.                 }
  48.  
  49.                 foreach (DateTime dt in DateTimeField)
  50.                 {
  51.                     Console.WriteLine("DateTimeField: " + dt);
  52.                 }
  53.  
  54.                 foreach (string richText in RichTextField)
  55.                 {
  56.                     Console.WriteLine("RichTextField: " + richText);
  57.                 }
  58.  
  59.                 foreach (AssetMetadata asset in AssetField)
  60.                 {
  61.                     Console.WriteLine("AssetField: " + asset.Url);
  62.                 }
  63.             }
  64.         }
  65.  
  66.         static void Main(string[] args)
  67.         {
  68.             ContentstackClient stack = new ContentstackClient(new ContentstackOptions()
  69.             {
  70.                 ApiKey = "blt94519f01d8f92c86",
  71.                 AccessToken = "cs99af6674ef2a7a53770da6b7",
  72.                 Environment = "contentdelivery",
  73.             });
  74.             stack.ContentType("fieldtypes").Entry("blt63b6985324826b78"
  75.                 ).Fetch<FieldTypesEntry>().GetAwaiter().GetResult().Render();
  76.         }
  77.     }
  78. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement