Пример #1
0
        public void Should_remove_null_values_from_name_model_when_cleaning()
        {
            var input =
                new NamedContentData()
                .AddField("field1", null)
                .AddField("field2",
                          new ContentFieldData()
                          .AddValue("en", 2)
                          .AddValue("it", null));

            var actual = input.ToCleaned();

            var expected =
                new NamedContentData()
                .AddField("field2",
                          new ContentFieldData()
                          .AddValue("en", 2));

            Assert.Equal(expected, actual);
        }
Пример #2
0
        public async Task <IActionResult> PostContent(string app, string name, [FromBody] NamedContentData request, [FromQuery] bool publish = false)
        {
            await contentQuery.ThrowIfSchemaNotExistsAsync(Context(), name);

            var publishPermission = Permissions.ForApp(Permissions.AppContentsPublish, app, name);

            if (publish && !User.Permissions().Includes(publishPermission))
            {
                return(new StatusCodeResult(123));
            }

            var command = new CreateContent {
                ContentId = Guid.NewGuid(), Data = request.ToCleaned(), Publish = publish
            };

            var context = await CommandBus.PublishAsync(command);

            var result   = context.Result <EntityCreatedResult <NamedContentData> >();
            var response = ContentDto.FromCommand(command, result);

            return(CreatedAtAction(nameof(GetContent), new { id = command.ContentId }, response));
        }