Nelze vybrat více než 25 témat Téma musí začínat písmenem nebo číslem, může obsahovat pomlčky („-“) a může být dlouhé až 35 znaků.

TechnologyService.cs 2.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  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. _logger.LogInformation("Start getting all technologies");
  17. var technologies = await _context.Technologies.ToListAsync();
  18. _logger.LogInformation($"Received {technologies.Count} technologies from database");
  19. _logger.LogInformation("Mapping received technologies to TechnologyResponseDto");
  20. var technologiesDto = _mapper.Map<List<TechnologyResponseDto>>(technologies);
  21. _logger.LogInformation($"Technologies mapped successfully");
  22. return technologiesDto;
  23. }
  24. public async Task<TechnologyResponseDto> GetByIdAsync(int id)
  25. {
  26. _logger.LogInformation($"Start searching Techology with id = {id}");
  27. var technology = await _context.Technologies.FindAsync(id);
  28. if (technology is null)
  29. {
  30. _logger.LogError($"Technology with id = {id} not found");
  31. throw new EntityNotFoundException("Technology not found");
  32. }
  33. _logger.LogInformation($"Mapping Technology with id = {id}");
  34. var result = _mapper.Map<TechnologyResponseDto>(technology);
  35. _logger.LogInformation($"Technology with id = {id} mapped successfully");
  36. return result;
  37. }
  38. public async Task<Technology> GetEntityByIdAsync(int id)
  39. {
  40. _logger.LogInformation($"Start searching Ad with id = {id}");
  41. var technology = await _context.Technologies.FindAsync(id);
  42. if (technology is null)
  43. {
  44. _logger.LogError($"Technology with id = {id} not found");
  45. throw new EntityNotFoundException("Technology not found");
  46. }
  47. _logger.LogInformation($"Technology with id = {id} found successfully");
  48. return technology;
  49. }
  50. public async Task<List<Technology>> GetEntitiesAsync(int[] technologiesIds)
  51. {
  52. _logger.LogInformation("Start getting all technologies");
  53. var technologies = await _context.Technologies.Where(x => technologiesIds.Contains(x.TechnologyId)).ToListAsync();
  54. _logger.LogInformation($"Received {technologies.Count} technologies from database");
  55. return technologies;
  56. }
  57. }
  58. }