コード例 #1
0
        public async Task ExecuteAsync(CommentCreateCommand command)
        {
            var item = command.Input.Map <Comment>();

            item.Id         = Guid.NewGuid();
            item.CreateTime = DateTime.Now;
            await commentRepository.InsertAsync(item);
        }
コード例 #2
0
 public async Task CommentPost(CommentCreateDto dto)
 {
     ValidateModelOrThrow();
     var command = new CommentCreateCommand()
     {
         Input = dto
     };
     await CommandBus.SendAsync(command);
 }
コード例 #3
0
 public async Task <ActionResult <Comment> > CreateComment([FromBody] CommentCreateCommand coment)
 {
     try
     {
         return(await _mediator.Send(mapper.Map <CommentCreateCommand>(coment)));
     }
     catch (Exception ex)
     {
         throw;
     }
 }
コード例 #4
0
        public void CommentCreateCommandHandler_Handle()
        {
            var user        = FakeObjects.TestUserWithId();
            var observation = FakeObjects.TestObservationWithId();

            Observation savedObservation = null;
            Comment     comment          = null;

            var command = new CommentCreateCommand()
            {
                Comment        = FakeValues.Comment,
                CommentedOn    = FakeValues.CreatedDateTime,
                ContributionId = observation.Id,
                UserId         = user.Id
            };

            //using (var session = _store.OpenSession(DocumentStoreHelper.TestDb))
            using (var session = _store.OpenSession())
            {
                session.Store(user);
                session.Store(observation);
                session.SaveChanges();

                var commandHandler = new CommentCreateCommandHandler(session);

                commandHandler.Handle(command);

                session.SaveChanges();

                savedObservation = session.Query <Observation>()
                                   .Where(x => x.Id == observation.Id)
                                   .FirstOrDefault();

                Assert.IsTrue(savedObservation.Comments.IsNotNullAndHasItems());

                comment = savedObservation.Comments.ToList()[0];
            }

            Assert.IsNotNull(comment);
            Assert.AreEqual(command.Comment, comment.Message);
            Assert.AreEqual(command.CommentedOn, comment.CommentedOn);
            Assert.AreEqual(command.UserId, comment.User.Id);
        }
コード例 #5
0
ファイル: CommentsController.cs プロジェクト: jbuiss0n/blog
        public async Task <ActionResult> Post(int post, [FromBody] CommentCreateCommand command)
        {
            if (post != command.Id_Post)
            {
                return(NotFound());
            }

            var result = await m_commandResolver.Publish <CommentCreateCommand, CommentCreateResult>(command);

            if (result.Exception != null)
            {
                return(StatusCode((int)HttpStatusCode.InternalServerError));
            }

            if (result.ValidationErrors.Any())
            {
                return(BadRequest(result.ValidationErrors));
            }

            return(CreatedAtAction(nameof(Get), new { post, id = result.Created }, result));
        }
コード例 #6
0
 public Task CreateComment([FromBody] CommentCreateCommand commentCreateCommand, CancellationToken cancellationToken)
 {
     return(mediator.Send(commentCreateCommand, cancellationToken));
 }
コード例 #7
0
 public CommentCreateResult CreateComment(Post post, CommentCreateCommand command)
 {
     return(m_resolver.Publish <CommentCreateCommand, CommentCreateResult>(command).Result);
 }
コード例 #8
0
ファイル: CommentController.cs プロジェクト: Dagar007/Pakshya
 public async Task <ActionResult <CommentDto> > Create(CommentCreateCommand command)
 {
     return(await Mediator.Send(command));
 }