2023-04-02 01:17:44 +04:00
|
|
|
|
using Microsoft.AspNetCore.Mvc;
|
2023-04-01 23:47:54 +04:00
|
|
|
|
|
|
|
|
|
namespace BlacksmithWorkshopRestApi.Controllers
|
|
|
|
|
{
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// в этом контроллере логика по заказам и изделиям
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
|
|
|
|
//настройка у контроллера, так как снова используем несколько Post и Get запросов
|
|
|
|
|
[Route("api/[controller]/[action]")]
|
|
|
|
|
[ApiController]
|
2023-04-02 01:17:44 +04:00
|
|
|
|
public class MainClientController : Controller
|
2023-04-01 23:47:54 +04:00
|
|
|
|
{
|
|
|
|
|
private readonly ILogger _logger;
|
|
|
|
|
|
|
|
|
|
private readonly IOrderLogic _order;
|
|
|
|
|
|
|
|
|
|
private readonly IManufactureLogic _manufacture;
|
|
|
|
|
|
2023-04-02 01:17:44 +04:00
|
|
|
|
public MainClientController(ILogger<MainClientController> logger, IOrderLogic order, IManufactureLogic manufacture)
|
2023-04-01 23:47:54 +04:00
|
|
|
|
{
|
|
|
|
|
_logger = logger;
|
|
|
|
|
_order = order;
|
|
|
|
|
_manufacture = manufacture;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[HttpGet]
|
|
|
|
|
public List<ManufactureViewModel>? GetManufactureList()
|
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
return _manufacture.ReadList(null);
|
|
|
|
|
}
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
|
|
|
|
_logger.LogError(ex, "Ошибка получения списка изделий");
|
|
|
|
|
throw;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[HttpGet]
|
|
|
|
|
public ManufactureViewModel? GetManufacture(int manufactureId)
|
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
return _manufacture.ReadElement(new ManufactureSearchModel
|
|
|
|
|
{
|
|
|
|
|
Id = manufactureId
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
|
|
|
|
_logger.LogError(ex, "Ошибка получения изделия по id={Id}", manufactureId);
|
|
|
|
|
throw;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[HttpGet]
|
|
|
|
|
public List<OrderViewModel>? GetOrders(int clientId)
|
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
return _order.ReadList(new OrderSearchModel
|
|
|
|
|
{
|
|
|
|
|
ClientId = clientId
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
|
|
|
|
_logger.LogError(ex, "Ошибка получения списка заказов клиента id ={ Id}", clientId);
|
|
|
|
|
throw;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[HttpPost]
|
|
|
|
|
public void CreateOrder(OrderBindingModel model)
|
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
_order.CreateOrder(model);
|
|
|
|
|
}
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
|
|
|
|
_logger.LogError(ex, "Ошибка создания заказа");
|
|
|
|
|
throw;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|