64 lines
1.7 KiB
C#
64 lines
1.7 KiB
C#
using ComputerStoreContracts.BindingModels;
|
|
using ComputerStoreContracts.BusinessLogicContracts;
|
|
using ComputerStoreContracts.SearchModels;
|
|
using ComputerStoreContracts.ViewModels;
|
|
using Microsoft.AspNetCore.Mvc;
|
|
|
|
namespace ComputerStoreRestAPI.Controllers
|
|
{
|
|
[Route("api/[controller]/[action]")]
|
|
[ApiController]
|
|
public class EmployeeController : Controller
|
|
{
|
|
private readonly ILogger _logger;
|
|
private readonly IEmployeeLogic _logic;
|
|
|
|
public EmployeeController(IEmployeeLogic logic, ILogger<EmployeeController> logger)
|
|
{
|
|
_logger = logger;
|
|
_logic = logic;
|
|
}
|
|
|
|
[HttpGet]
|
|
public EmployeeViewModel? Login(string login, string password)
|
|
{
|
|
try
|
|
{
|
|
return _logic.ReadElement(new EmployeeSearchModel { Username = login, Password = password });
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
_logger.LogError(ex, "Employee logging in error"); throw;
|
|
}
|
|
}
|
|
|
|
[HttpPost]
|
|
public bool Register(EmployeeBindingModel employee)
|
|
{
|
|
try
|
|
{
|
|
return _logic.Create(employee);
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
_logger.LogError(ex, "Employee registration error ");
|
|
throw;
|
|
}
|
|
}
|
|
|
|
[HttpPatch]
|
|
public bool UpdateData(EmployeeBindingModel employee)
|
|
{
|
|
try
|
|
{
|
|
return _logic.Update(employee);
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
_logger.LogError(ex, "Update of data error ");
|
|
throw;
|
|
}
|
|
}
|
|
}
|
|
}
|