public async Task Post(PostCreateDtoParam param)
 {
     ValidateModelOrThrow();
     var command = new PostCreateCommand()
     {
         Input = new PostCreateDto(param)
     };
     await CommandBus.SendAsync(command);
 }
示例#2
0
 public async Task Post(PostCreateDtoParam param)
 {
     ValidateModelOrThrow();
     //PostQuery.SelectAsync(title)
     throw new InputError("title 不能重复!");
     var command = new PostCreateCommand()
     {
         Input = new PostCreateDto(param)
     };
     await CommandBus.SendAsync(command);
 }
示例#3
0
 public async Task <ActionResult <Post> > CreatePost([FromBody] PostCreateCommand post)
 {
     try
     {
         return(await _mediator.Send(mapper.Map <PostCreateCommand>(post)));
     }
     catch (Exception ex)
     {
         throw;
     }
 }
示例#4
0
        public void PostCreateCommandHandler_Handle()
        {
            var user               = FakeObjects.TestUserWithId();
            var project            = FakeObjects.TestProjectWithId();
            var imageMediaResource = FakeObjects.TestImageMediaResourceWithId();

            Post newValue = null;

            var command = new PostCreateCommand()
            {
                UserId         = user.Id,
                GroupId        = project.Id,
                MediaResources = new List <string>()
                {
                    imageMediaResource.Id
                },
                Message   = FakeValues.Message,
                Subject   = FakeValues.Subject,
                Timestamp = FakeValues.CreatedDateTime
            };

            using (var session = _store.OpenSession())
            {
                session.Store(user);
                session.Store(project);
                session.Store(imageMediaResource);

                var commandHandler = new PostCreateCommandHandler(session);

                commandHandler.Handle(command);

                session.SaveChanges();

                newValue = session.Query <Post>().FirstOrDefault();
            }

            Assert.IsNotNull(newValue);
            //Assert.AreEqual(user.DenormalisedUserReference(), newValue.User);
            //Assert.AreEqual(project.DenormalisedNamedDomainModelReference(), newValue.Project);
            //Assert.IsTrue(newValue.MediaResources.Count == 1);
            //Assert.AreEqual(imageMediaResource, newValue.MediaResources[0]);
            Assert.AreEqual(command.Message, newValue.Message);
            Assert.AreEqual(command.Subject, newValue.Subject);
            Assert.AreEqual(command.Timestamp, newValue.CreatedOn);
        }
示例#5
0
        public async Task <IActionResult> CreatePost(PostCreateCommand command)
        {
            CreationResult <Post> createResult = Post.Create(command);

            if (createResult.Ok)
            {
                var hookResult = await EventStore.AppendAll(createResult.DomainEvents);

                if (hookResult.Ok)
                {
                    await PostRepository.CreatePost(createResult.CreatedEntity);

                    return(new CreatedResult("uri", createResult.CreatedEntity));
                }
                return(new BadRequestObjectResult(hookResult.Errors));
            }
            return(new BadRequestObjectResult(createResult.DomainErrors));
        }
示例#6
0
        public async Task <ActionResult> Post([FromBody] PostCreateCommand command)
        {
            var result = await m_commandResolver.Publish <PostCreateCommand, PostCreateResult>(command);

            return(CreateOrEditResult(result.Created, result));
        }
示例#7
0
 public async Task <IActionResult> CreatePost([FromBody] PostCreateCommand command)
 {
     return(await Handler.CreatePost(command));
 }