public async Task <IActionResult> CreateAsync([FromBody] CreateNewsCommand command) { if (command == null) { return(BadRequest()); } var @event = new CreateNewsEvent { Name = command.Name, Description = command.Description }; var value = JsonSerializer.Serialize(@event); var message = new Message <Null, string> { Value = value }; using var producer = _producerBuilder.Build(); await producer.ProduceAsync(Topic, message); return(Ok()); }
public async Task <IActionResult> Post([FromBody] NewsFormModel model, [FromServices] IMapper mapper) { var command = new CreateNewsCommand(CurrentUser); mapper.Map(model, command); var newsId = await Mediator.Send(command); return(Created(await GetNewsById(newsId))); }
public async Task <bool> Save(CreateNewsCommand request) { Log.ForContext <CreateNewsCommandHandler>() .Information("CreateNewsCommandRequest Model : {@request}", JsonSerializer.Serialize(request)); News news = new News(request.AgencyCode, request.NewsContent, true); news.CreateNewsMessage(); bool result = await _newsRepository.Save(news); return(result); }