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

GetRequestHandler.cs 1.0KB

1234567891011121314151617181920212223242526272829303132333435
  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.Queries;
  5. using MediatR;
  6. namespace Diligent.WebAPI.Host.Mediator.Request.Handlers
  7. {
  8. public class GetRequestHandler : IRequestHandler<GetRequestQuery, Data.Entities.Request>
  9. {
  10. private readonly IRequestRepository _requestService;
  11. public GetRequestHandler(IRequestRepository requestService)
  12. {
  13. _requestService = requestService;
  14. }
  15. public async Task<Data.Entities.Request> Handle(GetRequestQuery request, CancellationToken cancellationToken)
  16. {
  17. if (request.Id == null)
  18. {
  19. throw new BadHttpRequestException("Id cannot be null");
  20. }
  21. var req = await _requestService.GetByIdAsync(request.Id);
  22. if (request == null)
  23. {
  24. throw new NotFoundException("Request not found");
  25. }
  26. return req;
  27. }
  28. }
  29. }