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.

AcceptCustomerRequestHandler.cs 1.2KB

123456789101112131415161718192021222324252627282930313233
  1. using Diligent.WebAPI.Business.Services;
  2. using Diligent.WebAPI.Host.Exceptions;
  3. using Diligent.WebAPI.Host.Mediator.Request.Commands;
  4. using MediatR;
  5. namespace Diligent.WebAPI.Host.Mediator.Request.Handlers
  6. {
  7. public class AcceptCustomerRequestHandler : IRequestHandler<AcceptCustomerRequestCommand, string?>
  8. {
  9. private readonly RequestService _requestService;
  10. private readonly RoomService _roomService;
  11. public AcceptCustomerRequestHandler(RequestService requestService,RoomService roomService)
  12. {
  13. _requestService = requestService;
  14. _roomService = roomService;
  15. }
  16. public async Task<string?> Handle(AcceptCustomerRequestCommand request, CancellationToken cancellationToken)
  17. {
  18. var result1 = await _roomService.AddCustomerToRoom(request.CustomerId, request.RoomId);
  19. if (!result1)
  20. throw new NotFoundException($"Room with id={request.RoomId} doesn't exist");
  21. var result2 = await _requestService.RemoveRequestAsync(request.CustomerId, request.RoomId);
  22. if (!result2.IsSuccess)
  23. throw new BadHttpRequestException("customerId or roomId is invalid");
  24. return result2.Id;
  25. }
  26. }
  27. }