Пример #1
0
        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());
        }
Пример #2
0
        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)));
        }
Пример #3
0
        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);
        }