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

AcceptCustomerRequestHandler.cs 1.3KB

123456789101112131415161718192021222324252627282930313233343536
  1. using Diligent.WebAPI.Business.Interfaces;
  2. using Diligent.WebAPI.Business.Services;
  3. using Diligent.WebAPI.Host.Exceptions;
  4. using Diligent.WebAPI.Host.Mediator.Request.Commands;
  5. using MediatR;
  6. namespace Diligent.WebAPI.Host.Mediator.Request.Handlers
  7. {
  8. public class AcceptCustomerRequestHandler : IRequestHandler<AcceptCustomerRequestCommand, string?>
  9. {
  10. private readonly IRequestRepository _requestRepository;
  11. private readonly RoomService _roomService;
  12. public AcceptCustomerRequestHandler(RoomService roomService, IRequestRepository requestRepository)
  13. {
  14. _roomService = roomService;
  15. _requestRepository = requestRepository;
  16. }
  17. public async Task<string?> Handle(AcceptCustomerRequestCommand request, CancellationToken cancellationToken)
  18. {
  19. var result1 = await _roomService.AddCustomerToRoom(request.CustomerId, request.RoomId);
  20. if (!result1)
  21. throw new NotFoundException($"Room with id={request.RoomId} doesn't exist");
  22. var req = await _requestRepository.FindRequestAsync(request.CustomerId, request.RoomId);
  23. if (req == null)
  24. throw new NotFoundException("Request are not found");
  25. await _requestRepository.RemoveAsync(req.Id);
  26. return req.Id;
  27. }
  28. }
  29. }