namespace Diligent.WebAPI.Business.Services { public class TechnologyService : ITechnologyService { private readonly DatabaseContext _context; private readonly ILogger _logger; private readonly IMapper _mapper; public TechnologyService(IMapper mapper, DatabaseContext context, ILogger logger) { _mapper = mapper; _context = context; _logger = logger; } public async Task> GetAllAsync() { _logger.LogInformation("Start getting all technologies"); var technologies = await _context.Technologies.ToListAsync(); _logger.LogInformation($"Received {technologies.Count} technologies from database"); _logger.LogInformation("Mapping received technologies to TechnologyResponseDto"); var technologiesDto = _mapper.Map>(technologies); _logger.LogInformation($"Technologies mapped successfully"); return technologiesDto; } public async Task 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(technology); _logger.LogInformation($"Technology with id = {id} mapped successfully"); return result; } public async Task 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; } public async Task> GetEntitiesAsync(int[] technologiesIds) { _logger.LogInformation("Start getting all technologies"); var technologies = await _context.Technologies.Where(x => technologiesIds.Contains(x.TechnologyId)).ToListAsync(); _logger.LogInformation($"Received {technologies.Count} technologies from database"); return technologies; } } }