| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566 |
- 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()
- {
- _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<List<TechnologyResponseDto>>(technologies);
- _logger.LogInformation($"Technologies mapped successfully");
- return technologiesDto;
- }
-
- 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;
- }
-
- public async Task<List<Technology>> 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;
- }
- }
- }
|