82 lines
1.7 KiB
C#
82 lines
1.7 KiB
C#
using ComputerShopContracts.BindingModels;
|
|
using ComputerShopContracts.BusinessLogicContracts;
|
|
using ComputerShopContracts.SearchModels;
|
|
using ComputerShopContracts.ViewModels;
|
|
using Microsoft.AspNetCore.Mvc;
|
|
using System.Linq.Expressions;
|
|
|
|
namespace ComputerShopRestApi.Controllers
|
|
{
|
|
[Route("api/[controller]/[action]")]
|
|
[ApiController]
|
|
public class ShipmentController : Controller
|
|
{
|
|
private readonly ILogger _logger;
|
|
|
|
private readonly IShipmentLogic _logic;
|
|
|
|
public ShipmentController(IShipmentLogic logic, ILogger<ShipmentController> logger)
|
|
{
|
|
_logger = logger;
|
|
_logic = logic;
|
|
}
|
|
|
|
[HttpGet]
|
|
public ShipmentViewModel? GetShipment(int id)
|
|
{
|
|
try
|
|
{
|
|
return _logic.ReadElement(new ShipmentSearchModel
|
|
{
|
|
Id = id
|
|
});
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
_logger.LogError(ex, "Ошибка получения партии товара");
|
|
throw;
|
|
}
|
|
}
|
|
[HttpPost]
|
|
public void CreateShipment(ShipmentBindingModel model)
|
|
{
|
|
try
|
|
{
|
|
_logic.Create(model);
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
_logger.LogError(ex, "Ошибка создания партии товаров");
|
|
throw;
|
|
}
|
|
}
|
|
[HttpPost]
|
|
public void UpdateShipment(ShipmentBindingModel model)
|
|
{
|
|
try
|
|
{
|
|
_logic.Update(model);
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
_logger.LogError(ex, "Ошибка обновления партии товаров");
|
|
throw;
|
|
}
|
|
}
|
|
//!!!мб HttpPut
|
|
[HttpDelete]
|
|
public void DeleteShipment(ShipmentBindingModel model)
|
|
{
|
|
try
|
|
{
|
|
_logic.Delete(model);
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
_logger.LogError(ex, "Ошибка удаления партии товаров");
|
|
throw;
|
|
}
|
|
}
|
|
}
|
|
}
|