77 lines
2.3 KiB
C#
77 lines
2.3 KiB
C#
|
using AircraftPlantContracts.BindingModels;
|
|||
|
using AircraftPlantContracts.BusinessLogicsContracts;
|
|||
|
using AircraftPlantContracts.SearchModels;
|
|||
|
using AircraftPlantContracts.ViewModels;
|
|||
|
using DocumentFormat.OpenXml.Office2010.Excel;
|
|||
|
using Microsoft.AspNetCore.Mvc;
|
|||
|
|
|||
|
namespace AircraftPlantRestApi.Controllers
|
|||
|
{
|
|||
|
[Route("api/[controller]/[action]")]
|
|||
|
[ApiController]
|
|||
|
public class MainController : Controller
|
|||
|
{
|
|||
|
private readonly ILogger _logger;
|
|||
|
private readonly IOrderLogic _order;
|
|||
|
private readonly IPlaneLogic _plane;
|
|||
|
public MainController(ILogger<MainController> logger, IOrderLogic order, IPlaneLogic plane)
|
|||
|
{
|
|||
|
_logger = logger;
|
|||
|
_order = order;
|
|||
|
_plane = plane;
|
|||
|
}
|
|||
|
[HttpGet]
|
|||
|
public List<PlaneViewModel>? GetPlaneList()
|
|||
|
{
|
|||
|
try
|
|||
|
{
|
|||
|
return _plane.ReadList(null);
|
|||
|
}
|
|||
|
catch (Exception ex)
|
|||
|
{
|
|||
|
_logger.LogError(ex, "Ошибка получения списка изделий");
|
|||
|
throw;
|
|||
|
}
|
|||
|
}
|
|||
|
[HttpGet]
|
|||
|
public PlaneViewModel? GetPlane(int planeId)
|
|||
|
{
|
|||
|
try
|
|||
|
{
|
|||
|
return _plane.ReadElement(new PlaneSearchModel { Id = planeId });
|
|||
|
}
|
|||
|
catch (Exception ex)
|
|||
|
{
|
|||
|
_logger.LogError(ex, "Ошибка получения изделия с Id: {Id}",
|
|||
|
planeId);
|
|||
|
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;
|
|||
|
}
|
|||
|
}
|
|||
|
}
|
|||
|
}
|