114 lines
3.0 KiB
C#
114 lines
3.0 KiB
C#
using CarShowroomContracts.BusinessLogic;
|
|
using CarShowroomDataModels.Dtos;
|
|
using CarShowroomDataModels.SearchModel;
|
|
using CarShowroomDataModels.Views;
|
|
using Microsoft.AspNetCore.Mvc;
|
|
|
|
namespace CarShowroomRestApi.Controllers
|
|
{
|
|
[Route("api/[controller]/[action]")]
|
|
[ApiController]
|
|
public class EmployeeController : Controller
|
|
{
|
|
private readonly ILogger _logger;
|
|
private readonly IEmployeeLogic _logic;
|
|
|
|
public EmployeeController(ILogger<EmployeeController> logger, IEmployeeLogic employee)
|
|
{
|
|
_logger = logger;
|
|
_logic = employee;
|
|
}
|
|
|
|
[HttpGet]
|
|
public List<EmployeeView>? GetEmployeeList()
|
|
{
|
|
try
|
|
{
|
|
return _logic.ReadList(null);
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
_logger.LogError(ex, "Ошибка получения списка сотрудников");
|
|
throw;
|
|
}
|
|
}
|
|
|
|
[HttpGet]
|
|
public EmployeeView? GetEmployee(int EmployeeId)
|
|
{
|
|
try
|
|
{
|
|
return _logic.ReadElement(new EmployeeSearch
|
|
{
|
|
Id = EmployeeId
|
|
});
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
_logger.LogError(ex, "Ошибка получения сотрудника по Id={Id}", EmployeeId);
|
|
throw;
|
|
}
|
|
}
|
|
|
|
[HttpGet]
|
|
public EmployeeView? Login(string login, string password)
|
|
{
|
|
try
|
|
{
|
|
return _logic.ReadElement(new EmployeeSearch
|
|
{
|
|
Email = login,
|
|
Password = password
|
|
});
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
_logger.LogError(ex, "Ошибка входа в систему");
|
|
throw;
|
|
}
|
|
}
|
|
|
|
[HttpPost]
|
|
public void CreateEmployee(EmployeeDto model)
|
|
{
|
|
try
|
|
{
|
|
_logic.Create(model);
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
_logger.LogError(ex, "Ошибка создания сотрудника");
|
|
throw;
|
|
}
|
|
}
|
|
|
|
[HttpPut]
|
|
public void UpdateEmployee(EmployeeDto model)
|
|
{
|
|
try
|
|
{
|
|
_logic.Update(model);
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
_logger.LogError(ex, "Ошибка обновления сотрудника");
|
|
throw;
|
|
}
|
|
}
|
|
|
|
[HttpDelete]
|
|
public void DeleteEmployee(EmployeeDto model)
|
|
{
|
|
try
|
|
{
|
|
_logic.Delete(model);
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
_logger.LogError(ex, "Ошибка удаления сотрудника");
|
|
throw;
|
|
}
|
|
}
|
|
}
|
|
}
|