12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849 |
- using AutoMapper;
- using MTWorkHR.Application.Exceptions;
- using MTWorkHR.Application.Models;
- using MTWorkHR.Core.IRepositories;
- using MTWorkHR.Core.Logging;
- 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 ICompanyRepository _companyRepository;
- private readonly IMapper _mapper;
- private readonly IAppLogger<UserDto> _logger;
- public EmployeeService(ICompanyRepository companyRepository, IMapper mapper, IAppLogger<UserDto> logger)
- {
- _companyRepository = companyRepository;
- _mapper = mapper;
- _logger = logger;
- }
- public UserDto Get(int id)
- {
- var companyDto = new UserDto();
- try
- {
- var company = _companyRepository.GetByIdAsync(id);
- if (company == null)
- {
- _logger.LogWarning("NOT FOUND Company");
- throw new NotFoundException("company not in DB", id);
- }
- else
- _logger.LogInformation("OK _ Found company");
- _mapper.Map(company, companyDto);
- }catch(Exception e)
- {
- _logger.LogWarning($"company [{id}]" + e.Message);
- throw new BadRequest($"companyExc [{id}]" + e.Message);
- }
- return companyDto;
- }
- }
- }
|