Advertisement
Guest User

Untitled

a guest
Nov 21st, 2019
118
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.35 KB | None | 0 0
  1. namespace Fashionista.Application.ProductAttributes.Queries.GetColor
  2. {
  3. using System;
  4. using System.Threading;
  5. using System.Threading.Tasks;
  6.  
  7. using Fashionista.Application.Exceptions;
  8. using Fashionista.Application.Infrastructure;
  9. using Fashionista.Application.Interfaces;
  10. using Fashionista.Domain.Entities;
  11. using MediatR;
  12. using Microsoft.EntityFrameworkCore;
  13.  
  14. public class GetColorQueryHandler : IRequestHandler<GetColorQuery, ProductColor>
  15. {
  16. private readonly IDeletableEntityRepository<ProductColor> colorsRepository;
  17.  
  18. public GetColorQueryHandler(IDeletableEntityRepository<ProductColor> colorsRepository)
  19. {
  20. this.colorsRepository = colorsRepository;
  21. }
  22.  
  23. public async Task<ProductColor> Handle(GetColorQuery request, CancellationToken cancellationToken)
  24. {
  25. request = request ?? throw new ArgumentNullException(nameof(request));
  26.  
  27. if (!await CommonCheckAssistant.CheckIfProductColorExists(request.Name, this.colorsRepository))
  28. {
  29. throw new NotFoundException(nameof(ProductColor), request.Name);
  30. }
  31.  
  32. return await this.colorsRepository
  33. .AllAsNoTracking()
  34. .FirstOrDefaultAsync(x => x.Name == request.Name, cancellationToken);
  35. }
  36. }
  37. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement