12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849 |
- 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<UserDto> _logger;
- public EmployeeService(IEmployeeRepository employeeRepository, IMapper mapper, IAppLogger<UserDto> 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;
- }
- }
- }
|