public async Task ExecuteAsync(CommentCreateCommand command) { var item = command.Input.Map <Comment>(); item.Id = Guid.NewGuid(); item.CreateTime = DateTime.Now; await commentRepository.InsertAsync(item); }
public async Task CommentPost(CommentCreateDto dto) { ValidateModelOrThrow(); var command = new CommentCreateCommand() { Input = dto }; await CommandBus.SendAsync(command); }
public async Task <ActionResult <Comment> > CreateComment([FromBody] CommentCreateCommand coment) { try { return(await _mediator.Send(mapper.Map <CommentCreateCommand>(coment))); } catch (Exception ex) { throw; } }
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); }
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)); }
public Task CreateComment([FromBody] CommentCreateCommand commentCreateCommand, CancellationToken cancellationToken) { return(mediator.Send(commentCreateCommand, cancellationToken)); }
public CommentCreateResult CreateComment(Post post, CommentCreateCommand command) { return(m_resolver.Publish <CommentCreateCommand, CommentCreateResult>(command).Result); }
public async Task <ActionResult <CommentDto> > Create(CommentCreateCommand command) { return(await Mediator.Send(command)); }