2024-05-25 17:47:14 +04:00
|
|
|
|
using ElectronicsShopContracts.BindingModels;
|
2024-05-27 17:35:14 +04:00
|
|
|
|
using ElectronicsShopContracts.BusinessLogicContracts;
|
|
|
|
|
using ElectronicsShopContracts.SearchModels;
|
2024-05-25 17:47:14 +04:00
|
|
|
|
using ElectronicsShopContracts.ViewModels;
|
2024-05-27 18:33:24 +04:00
|
|
|
|
using ElectronicsShopDataBaseImplement.Models;
|
2024-05-30 20:32:16 +04:00
|
|
|
|
using ElectronicsShopDataModels.Models;
|
2024-05-25 17:47:14 +04:00
|
|
|
|
using Microsoft.AspNetCore.Mvc;
|
2024-04-29 21:57:01 +04:00
|
|
|
|
|
2024-05-27 17:35:14 +04:00
|
|
|
|
namespace ElectronicsShopRestAPI.Controllers {
|
2024-05-25 17:47:14 +04:00
|
|
|
|
|
|
|
|
|
[Route("api/[controller]/[action]")]
|
|
|
|
|
[ApiController]
|
2024-04-29 21:57:01 +04:00
|
|
|
|
public class MainController : Controller {
|
2024-05-25 17:47:14 +04:00
|
|
|
|
|
|
|
|
|
private readonly ILogger _logger;
|
2024-05-27 17:35:14 +04:00
|
|
|
|
private readonly IProductLogic _product;
|
2024-05-27 18:33:24 +04:00
|
|
|
|
private readonly IOrderLogic _order;
|
2024-05-30 20:32:16 +04:00
|
|
|
|
private Dictionary<int, (IProductModel, int)> _ProductList;
|
|
|
|
|
private int? _ID;
|
2024-05-25 17:47:14 +04:00
|
|
|
|
|
2024-05-27 22:05:47 +04:00
|
|
|
|
public MainController(ILogger<MainController> logger, IProductLogic product,
|
2024-05-28 12:50:24 +04:00
|
|
|
|
IOrderLogic orderLogic) {
|
2024-05-25 17:47:14 +04:00
|
|
|
|
_logger = logger;
|
2024-05-27 17:35:14 +04:00
|
|
|
|
_product = product;
|
2024-05-27 18:33:24 +04:00
|
|
|
|
_order = orderLogic;
|
2024-05-30 20:32:16 +04:00
|
|
|
|
_ProductList = new Dictionary<int, (IProductModel, int)>();
|
2024-05-25 17:47:14 +04:00
|
|
|
|
}
|
|
|
|
|
|
2024-05-28 12:50:24 +04:00
|
|
|
|
[HttpGet]
|
|
|
|
|
public List<ProductViewModel>? GetProducts() {
|
|
|
|
|
try {
|
|
|
|
|
return _product.ReadList(null);
|
|
|
|
|
}
|
|
|
|
|
catch (Exception ex) {
|
|
|
|
|
_logger.LogError(ex, $"Ошибка получения данных");
|
|
|
|
|
throw;
|
|
|
|
|
}
|
|
|
|
|
}
|
2024-05-29 15:31:22 +04:00
|
|
|
|
[HttpGet]
|
2024-05-29 21:21:17 +04:00
|
|
|
|
public ProductViewModel? GetProduct(int _productID)
|
2024-05-29 15:31:22 +04:00
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
return _product.ReadElement(new ProductSearchModel
|
|
|
|
|
{
|
2024-05-29 21:21:17 +04:00
|
|
|
|
ID = _productID
|
2024-05-29 15:31:22 +04:00
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
2024-05-29 21:21:17 +04:00
|
|
|
|
_logger.LogError(ex, "Ошибка получения товаров id={Id}", _productID);
|
2024-05-29 15:31:22 +04:00
|
|
|
|
throw;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
[HttpGet]
|
2024-05-27 17:35:14 +04:00
|
|
|
|
public List<OrderViewModel>? GetOrders(int _clientID) {
|
2024-05-27 18:33:24 +04:00
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
return _order.ReadList(new OrderSearchModel
|
|
|
|
|
{
|
|
|
|
|
ID = _clientID
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
|
|
|
|
_logger.LogError(ex, "Ошибка получения списка заказов клиента id = {Id} ", _clientID);
|
|
|
|
|
throw;
|
|
|
|
|
}
|
2024-05-25 17:47:14 +04:00
|
|
|
|
}
|
|
|
|
|
|
2024-05-30 20:32:16 +04:00
|
|
|
|
[HttpGet]
|
|
|
|
|
public OrderViewModel? GetOrder(int _clientID) {
|
|
|
|
|
try {
|
|
|
|
|
return _order.ReadElement(new OrderSearchModel { ClientID = _clientID });
|
|
|
|
|
}
|
|
|
|
|
catch (Exception ex) {
|
|
|
|
|
_logger.LogError(ex, $"Ошибка получения данных clientid = {_clientID}");
|
|
|
|
|
throw;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2024-05-27 17:35:14 +04:00
|
|
|
|
|
2024-05-25 17:47:14 +04:00
|
|
|
|
[HttpPost]
|
|
|
|
|
public void CreateOrder(OrderBindingModel model) {
|
2024-05-28 11:42:47 +04:00
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
_order.CreateOrder(model);
|
|
|
|
|
}
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
|
|
|
|
_logger.LogError(ex, "Ошибка создания заказа");
|
|
|
|
|
throw;
|
|
|
|
|
}
|
2024-05-25 17:47:14 +04:00
|
|
|
|
}
|
2024-05-29 18:32:24 +04:00
|
|
|
|
|
2024-05-30 20:32:16 +04:00
|
|
|
|
[HttpPost]
|
|
|
|
|
public void SaveOrder(Dictionary<int, (IProductModel, int)> list) {
|
|
|
|
|
|
|
|
|
|
}
|
2024-05-29 18:32:24 +04:00
|
|
|
|
}
|
2024-04-29 21:57:01 +04:00
|
|
|
|
}
|