Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

AddMessageHandler.cs 1000B

1234567891011121314151617181920212223242526272829303132
  1. using Diligent.WebAPI.Business.Interfaces;
  2. using Diligent.WebAPI.Business.Services;
  3. using Diligent.WebAPI.Data.Entities;
  4. using Diligent.WebAPI.Host.Exceptions;
  5. using Diligent.WebAPI.Host.Mediator.Messages.Commands;
  6. using MediatR;
  7. namespace Diligent.WebAPI.Host.Mediator.Messages.Handlers
  8. {
  9. public class AddMessageHandler : IRequestHandler<AddMessageCommand, Unit>
  10. {
  11. private readonly IRoomRepository _roomRepository;
  12. public AddMessageHandler(IRoomRepository roomRepository)
  13. {
  14. _roomRepository = roomRepository;
  15. }
  16. public async Task<Unit> Handle(AddMessageCommand request, CancellationToken cancellationToken)
  17. {
  18. var room = await _roomRepository.GetByIdAsync(request.roomId);
  19. if(room == null)
  20. {
  21. throw new NotFoundException("Room is not found");
  22. }
  23. await _roomRepository.AddMessage(room, request.message);
  24. return new Unit();
  25. }
  26. }
  27. }