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) {
|
2024-05-30 23:49:53 +04:00
|
|
|
|
_logger.LogError(ex, "Ошибка создания статьи");
|
2024-05-28 12:50:24 +04:00
|
|
|
|
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;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2024-05-30 13:08:24 +04:00
|
|
|
|
[HttpPost]
|
|
|
|
|
public void EditCostItem(CostItemBindingModel model) {
|
|
|
|
|
try {
|
|
|
|
|
_costItem.Update(model);
|
|
|
|
|
}
|
|
|
|
|
catch (Exception ex) {
|
|
|
|
|
_logger.LogError(ex, "Ошибка обновления данных");
|
|
|
|
|
throw;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[HttpPost]
|
|
|
|
|
public void DeleteCostItem(CostItemBindingModel model) {
|
|
|
|
|
try {
|
|
|
|
|
_costItem.Delete(model);
|
|
|
|
|
}
|
|
|
|
|
catch (Exception ex) {
|
|
|
|
|
_logger.LogError(ex, "Ошибка удаления статьи затрат");
|
|
|
|
|
throw;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2024-05-28 12:50:24 +04:00
|
|
|
|
[HttpPost]
|
|
|
|
|
public void CreateProduct(ProductBindingModel model) {
|
|
|
|
|
try {
|
|
|
|
|
_productLogic.Create(model);
|
|
|
|
|
}
|
|
|
|
|
catch(Exception ex) {
|
2024-05-29 21:21:17 +04:00
|
|
|
|
_logger.LogError(ex, "Ошибка создания товара");
|
|
|
|
|
throw;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[HttpPost]
|
|
|
|
|
public void EditProduct(ProductBindingModel model) {
|
|
|
|
|
try {
|
|
|
|
|
_productLogic.Update(model);
|
|
|
|
|
}
|
|
|
|
|
catch (Exception ex) {
|
|
|
|
|
_logger.LogError(ex, "Ошибка обновления товара");
|
2024-05-28 12:50:24 +04:00
|
|
|
|
throw;
|
|
|
|
|
}
|
|
|
|
|
}
|
2024-05-29 21:45:37 +04:00
|
|
|
|
|
|
|
|
|
[HttpPost]
|
|
|
|
|
public void DeleteProduct(ProductBindingModel model) {
|
|
|
|
|
try {
|
|
|
|
|
_productLogic.Delete(model);
|
|
|
|
|
}
|
|
|
|
|
catch (Exception ex) {
|
|
|
|
|
_logger.LogError(ex, "Ошибка удаления товара");
|
|
|
|
|
throw;
|
|
|
|
|
}
|
|
|
|
|
}
|
2024-05-27 14:57:41 +04:00
|
|
|
|
}
|
|
|
|
|
}
|