Du kannst nicht mehr als 25 Themen auswählen Themen müssen mit entweder einem Buchstaben oder einer Ziffer beginnen. Sie können Bindestriche („-“) enthalten und bis zu 35 Zeichen lang sein.

TechnologyService.cs 1.9KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. namespace Diligent.WebAPI.Business.Services
  2. {
  3. public class TechnologyService : ITechnologyService
  4. {
  5. private readonly DatabaseContext _context;
  6. private readonly ILogger<TechnologyService> _logger;
  7. private readonly IMapper _mapper;
  8. public TechnologyService(IMapper mapper, DatabaseContext context, ILogger<TechnologyService> logger)
  9. {
  10. _mapper = mapper;
  11. _context = context;
  12. _logger = logger;
  13. }
  14. public async Task<List<TechnologyResponseDto>> GetAllAsync()
  15. {
  16. return _mapper.Map<List<TechnologyResponseDto>>(await _context.Technologies.ToListAsync());
  17. }
  18. public async Task<TechnologyResponseDto> GetByIdAsync(int id)
  19. {
  20. _logger.LogInformation($"Start searching Techology with id = {id}");
  21. var technology = await _context.Technologies.FindAsync(id);
  22. if (technology is null)
  23. {
  24. _logger.LogError($"Technology with id = {id} not found");
  25. throw new EntityNotFoundException("Technology not found");
  26. }
  27. _logger.LogInformation($"Mapping Technology with id = {id}");
  28. var result = _mapper.Map<TechnologyResponseDto>(technology);
  29. _logger.LogInformation($"Technology with id = {id} mapped successfully");
  30. return result;
  31. }
  32. public async Task<Technology> GetEntityByIdAsync(int id)
  33. {
  34. _logger.LogInformation($"Start searching Ad with id = {id}");
  35. var technology = await _context.Technologies.FindAsync(id);
  36. if (technology is null)
  37. {
  38. _logger.LogError($"Technology with id = {id} not found");
  39. throw new EntityNotFoundException("Technology not found");
  40. }
  41. _logger.LogInformation($"Technology with id = {id} found successfully");
  42. return technology;
  43. }
  44. }
  45. }