using ElectronicsShopContracts.BindingModels; using ElectronicsShopContracts.BusinessLogicContracts; using ElectronicsShopContracts.SearchModels; using ElectronicsShopContracts.ViewModels; using ElectronicsShopDataBaseImplement.Models; using Microsoft.AspNetCore.Mvc; namespace ElectronicsShopRestAPI.Controllers { [Route("api/[controller]/[action]")] [ApiController] public class EmployeeController : Controller { private readonly ILogger _logger; private readonly IEmployeeLogic _logic; private readonly ICostItemLogic _costItem; private readonly IProductLogic _productLogic; public EmployeeController(ILogger logger, IEmployeeLogic logic, ICostItemLogic costItem, IProductLogic productLogic) { _logger = logger; _logic = logic; _costItem = costItem; _productLogic = productLogic; } [HttpGet] public EmployeeViewModel? Login(string login, string password) { try { return _logic.ReadElement(new EmployeeSearchModel { 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; } } [HttpPost] public void CreateCostItem(CostItemBindingModel model) { try { _costItem.Create(model); } catch (Exception ex) { _logger.LogError(ex, "Ошибка создания заказа"); throw; } } [HttpGet] public List? 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; } } } }