| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152 |
- namespace Diligent.WebAPI.Business.Services
- {
- public class TechnologyService : ITechnologyService
- {
- private readonly DatabaseContext _context;
- private readonly ILogger<TechnologyService> _logger;
- private readonly IMapper _mapper;
-
- public TechnologyService(IMapper mapper, DatabaseContext context, ILogger<TechnologyService> logger)
- {
- _mapper = mapper;
- _context = context;
- _logger = logger;
- }
-
- public async Task<List<TechnologyResponseDto>> GetAllAsync()
- {
- return _mapper.Map<List<TechnologyResponseDto>>(await _context.Technologies.ToListAsync());
- }
-
- public async Task<TechnologyResponseDto> GetByIdAsync(int id)
- {
- _logger.LogInformation($"Start searching Techology with id = {id}");
- var technology = await _context.Technologies.FindAsync(id);
-
- if (technology is null)
- {
- _logger.LogError($"Technology with id = {id} not found");
- throw new EntityNotFoundException("Technology not found");
- }
- _logger.LogInformation($"Mapping Technology with id = {id}");
- var result = _mapper.Map<TechnologyResponseDto>(technology);
- _logger.LogInformation($"Technology with id = {id} mapped successfully");
- return result;
- }
-
- public async Task<Technology> GetEntityByIdAsync(int id)
- {
- _logger.LogInformation($"Start searching Ad with id = {id}");
- var technology = await _context.Technologies.FindAsync(id);
-
- if (technology is null)
- {
- _logger.LogError($"Technology with id = {id} not found");
- throw new EntityNotFoundException("Technology not found");
- }
-
- _logger.LogInformation($"Technology with id = {id} found successfully");
- return technology;
- }
- }
- }
|