2024-05-27 14:57:41 +04:00
|
|
|
|
using ElectronicsShopContracts.BindingModels;
|
|
|
|
|
using ElectronicsShopContracts.BusinessLogicContracts;
|
|
|
|
|
using ElectronicsShopContracts.SearchModels;
|
|
|
|
|
using ElectronicsShopContracts.ViewModels;
|
2024-05-28 12:50:24 +04:00
|
|
|
|
using ElectronicsShopDataBaseImplement.Models;
|
2024-05-27 14:57:41 +04:00
|
|
|
|
using Microsoft.AspNetCore.Mvc;
|
|
|
|
|
|
|
|
|
|
namespace ElectronicsShopRestAPI.Controllers {
|
|
|
|
|
|
|
|
|
|
[Route("api/[controller]/[action]")]
|
|
|
|
|
[ApiController]
|
|
|
|
|
|
|
|
|
|
public class EmployeeController : Controller {
|
|
|
|
|
|
|
|
|
|
private readonly ILogger _logger;
|
|
|
|
|
private readonly IEmployeeLogic _logic;
|
2024-05-28 12:50:24 +04:00
|
|
|
|
private readonly ICostItemLogic _costItem;
|
|
|
|
|
private readonly IProductLogic _productLogic;
|
2024-05-27 14:57:41 +04:00
|
|
|
|
|
2024-05-28 12:50:24 +04:00
|
|
|
|
public EmployeeController(ILogger<EmployeeController> logger, IEmployeeLogic logic, ICostItemLogic costItem, IProductLogic productLogic) {
|
2024-05-27 14:57:41 +04:00
|
|
|
|
_logger = logger;
|
|
|
|
|
_logic = logic;
|
2024-05-28 12:50:24 +04:00
|
|
|
|
_costItem = costItem;
|
|
|
|
|
_productLogic = productLogic;
|
2024-05-27 14:57:41 +04:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[HttpGet]
|
|
|
|
|
public EmployeeViewModel? Login(string login, string password) {
|
|
|
|
|
try {
|
2024-05-27 17:35:14 +04:00
|
|
|
|
return _logic.ReadElement(new EmployeeSearchModel {
|
2024-05-27 14:57:41 +04:00
|
|
|
|
Login = login,
|
|
|
|
|
Password = password
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
catch (Exception ex) {
|
|
|
|
|
_logger.LogError(ex, "Ошибка входа в систему");
|
|
|
|
|
throw;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[HttpPost]
|
|
|
|
|
public void Register(EmployeeBindingModel model) {
|
|
|
|
|
try {
|
|
|
|
|
_logic.Create(model);
|
|
|
|
|
}
|
|
|
|
|
catch (Exception ex) {
|
|
|
|
|
_logger.LogError(ex, "Ошибка регистрации");
|
|
|
|
|
throw;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[HttpPost]
|
|
|
|
|
public void UpdateData(EmployeeBindingModel model) {
|
|
|
|
|
try {
|
|
|
|
|
_logic.Update(model);
|
|
|
|
|
}
|
|
|
|
|
catch (Exception ex) {
|
|
|
|
|
_logger.LogError(ex, "Ошибка обновления данных");
|
|
|
|
|
throw;
|
|
|
|
|
}
|
|
|
|
|
}
|
2024-05-28 12:50:24 +04:00
|
|
|
|
|
|
|
|
|
[HttpPost]
|
|
|
|
|
public void CreateCostItem(CostItemBindingModel model) {
|
|
|
|
|
try {
|
|
|
|
|
_costItem.Create(model);
|
|
|
|
|
}
|
|
|
|
|
catch (Exception ex) {
|
|
|
|
|
_logger.LogError(ex, "Ошибка создания заказа");
|
|
|
|
|
throw;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[HttpGet]
|
|
|
|
|
public List<CostItemViewModel>? GetCostItems(int _employeeID) {
|
|
|
|
|
try {
|
|
|
|
|
return _costItem.ReadList(new CostItemSearchModel { EmployeeID = _employeeID });
|
|
|
|
|
}
|
|
|
|
|
catch (Exception ex) {
|
|
|
|
|
_logger.LogError(ex, $"Ошибка получения данных списка заказов сотрудника ID ={_employeeID}");
|
|
|
|
|
throw;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[HttpGet]
|
|
|
|
|
public CostItemViewModel? GetCostItem(int _costItemID) {
|
|
|
|
|
try {
|
|
|
|
|
return _costItem.ReadElement(new CostItemSearchModel { ID = _costItemID });
|
|
|
|
|
}
|
|
|
|
|
catch (Exception ex) {
|
|
|
|
|
_logger.LogError(ex, $"Ошибка получения статьи затрат ID={_costItemID}");
|
|
|
|
|
throw;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[HttpPost]
|
|
|
|
|
public void CreateProduct(ProductBindingModel model) {
|
|
|
|
|
try {
|
|
|
|
|
_productLogic.Create(model);
|
|
|
|
|
}
|
|
|
|
|
catch(Exception ex) {
|
|
|
|
|
_logger.LogError(ex, "Ошибка создания заказа");
|
|
|
|
|
throw;
|
|
|
|
|
}
|
|
|
|
|
}
|
2024-05-27 14:57:41 +04:00
|
|
|
|
}
|
|
|
|
|
}
|