You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

AddMessageHandler.cs 852B

123456789101112131415161718192021222324252627
  1. using Diligent.WebAPI.Business.Services;
  2. using Diligent.WebAPI.Data.Entities;
  3. using Diligent.WebAPI.Host.Exceptions;
  4. using Diligent.WebAPI.Host.Mediator.Messages.Commands;
  5. using MediatR;
  6. namespace Diligent.WebAPI.Host.Mediator.Messages.Handlers
  7. {
  8. public class AddMessageHandler : IRequestHandler<AddMessageCommand, Unit>
  9. {
  10. private readonly RoomService _roomService;
  11. public AddMessageHandler(RoomService roomService)
  12. {
  13. _roomService = roomService;
  14. }
  15. public async Task<Unit> Handle(AddMessageCommand request, CancellationToken cancellationToken)
  16. {
  17. var result = await _roomService.AddMessage(request.roomId,request.message);
  18. if (!result)
  19. throw new NotFoundException("Room id doesn't exist");
  20. return new Unit();
  21. }
  22. }
  23. }