using AutoMapper; using MTWorkHR.Application.Exceptions; using MTWorkHR.Application.Logging; using MTWorkHR.Application.Models; using MTWorkHR.Core.IRepositories; using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace MTWorkHR.Application.Services { public class EmployeeService { private readonly IEmployeeRepository _employeeRepository; private readonly IMapper _mapper; private readonly IAppLogger _logger; public EmployeeService(IEmployeeRepository employeeRepository, IMapper mapper, IAppLogger logger) { _employeeRepository = employeeRepository; _mapper = mapper; _logger = logger; } public UserDto Get(int id) { var employeeDto = new UserDto(); try { var emp = _employeeRepository.GetByIdAsync(id); if (emp == null) { _logger.LogWarning("NOT FOUND Emp"); throw new NotFoundException("Employee not in DB", id); } else _logger.LogInformation("OK _ Found Employee"); _mapper.Map(emp, employeeDto); }catch(Exception e) { _logger.LogWarning($"emp [{id}]" + e.Message); throw new BadRequest($"empExc [{id}]" + e.Message); } return employeeDto; } } }