Пример #1
0
        protected static IContentEntity CreateContent(Guid id, Guid refId, Guid assetId, NamedContentData data = null, bool noJson = false)
        {
            var now = DateTime.UtcNow.ToInstant();

            data = data ??
                   new NamedContentData()
                   .AddField("my-string",
                             new ContentFieldData()
                             .AddValue("de", "value"))
                   .AddField("my-assets",
                             new ContentFieldData()
                             .AddValue("iv", JToken.FromObject(new[] { assetId })))
                   .AddField("my-number",
                             new ContentFieldData()
                             .AddValue("iv", 1))
                   .AddField("my-boolean",
                             new ContentFieldData()
                             .AddValue("iv", true))
                   .AddField("my-datetime",
                             new ContentFieldData()
                             .AddValue("iv", now.ToDateTimeUtc()))
                   .AddField("my-tags",
                             new ContentFieldData()
                             .AddValue("iv", JToken.FromObject(new[] { "tag1", "tag2" })))
                   .AddField("my-references",
                             new ContentFieldData()
                             .AddValue("iv", JToken.FromObject(new[] { refId })))
                   .AddField("my-geolocation",
                             new ContentFieldData()
                             .AddValue("iv", JToken.FromObject(new { latitude = 10, longitude = 20 })));

            if (!noJson)
            {
                data.AddField("my-json",
                              new ContentFieldData()
                              .AddValue("iv", JToken.FromObject(new { value = 1 })));
            }

            var content = new ContentEntity
            {
                Id             = id,
                Version        = 1,
                Created        = now,
                CreatedBy      = new RefToken("subject", "user1"),
                LastModified   = now,
                LastModifiedBy = new RefToken("subject", "user2"),
                Data           = data
            };

            return(content);
        }