CourseWork_CompShop/ComputerShopProvider/ComputerShopRestApi/Controllers/EquipmentReceivingController.cs

66 lines
2.0 KiB
C#
Raw Normal View History

2023-05-20 08:34:33 +04:00
using ComputerShopContracts.BindingModels;
using ComputerShopContracts.BusinessLogicContracts;
using ComputerShopContracts.SearchModels;
using ComputerShopContracts.ViewModels;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
namespace ComputerShopRestApi.Controllers
{
[Route("api/[controller]/[action]")]
[ApiController]
public class EquipmentReceivingController : Controller
{
2023-05-20 08:34:33 +04:00
private readonly ILogger _logger;
private readonly IEquipmentReceivingLogic _equipmentReceiving;
public EquipmentReceivingController(ILogger<MainController> logger, IEquipmentReceivingLogic equipmentReceiving)
{
_logger = logger;
_equipmentReceiving = equipmentReceiving;
}
[HttpGet]
public List<EquipmentReceivingViewModel>? GetReceivingList()
{
try
{
return _equipmentReceiving.ReadList(null);
}
catch (Exception ex)
{
_logger.LogError(ex, "Ошибка получения списка компонентов");
throw;
}
}
[HttpGet]
public List<EquipmentReceivingViewModel>? GetReceivings(int clientId)
{
try
{
return _equipmentReceiving.ReadList(new EquipmentReceivingSearchModel
{
ClientId = clientId
});
}
catch (Exception ex)
{
_logger.LogError(ex, "Ошибка получения списка закупок клиента id ={ Id}", clientId);
throw;
}
}
[HttpPost]
public void CreateReceiving(EquipmentReceivingBindingModel model)
{
try
{
_equipmentReceiving.Create(model);
}
catch (Exception ex)
{
_logger.LogError(ex, "Ошибка создания получения");
throw;
}
}
}
}