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.

RemoveUserFromGroupHandler.cs 1.2KB

123456789101112131415161718192021222324252627282930313233343536373839
  1. using Diligent.WebAPI.Business.Interfaces;
  2. using Diligent.WebAPI.Business.Services;
  3. using Diligent.WebAPI.Host.Exceptions;
  4. using Diligent.WebAPI.Host.Mediator.Rooms.Commands;
  5. using MediatR;
  6. namespace Diligent.WebAPI.Host.Mediator.Chat.Handlers
  7. {
  8. public class RemoveUserFromGroupHandler : IRequestHandler<RemoveUserFromGroupCommand, Unit>
  9. {
  10. private readonly IRoomRepository _roomRepository;
  11. public RemoveUserFromGroupHandler(IRoomRepository roomRepository)
  12. {
  13. _roomRepository = roomRepository;
  14. }
  15. public async Task<Unit> Handle(RemoveUserFromGroupCommand request, CancellationToken cancellationToken)
  16. {
  17. var room = await _roomRepository.GetByIdAsync(request.RoomId);
  18. if(room == null)
  19. {
  20. throw new NotFoundException("Room is not found");
  21. }
  22. var userConnection = room.Customers.Where(x => x.CustomerId == request.UserId).FirstOrDefault();
  23. if(userConnection == null)
  24. {
  25. throw new NotFoundException("User connection is not found");
  26. }
  27. await _roomRepository.LeaveChatRoom(room, userConnection);
  28. return new Unit();
  29. }
  30. }
  31. }