Computer_Hardware_Store/HardwareShop/HardwareShopRestApi/Controllers/MainController.cs

67 lines
1.6 KiB
C#
Raw Normal View History

2023-04-02 19:27:58 +04:00
using HardwareShopContracts.BindingModels;
using HardwareShopContracts.BusinessLogicsContracts;
using Microsoft.AspNetCore.Mvc;
namespace HardwareShopRestApi.Controllers
{
[Route("api/[controller]/[action]")]
[ApiController]
public class MainController : Controller
{
private readonly ILogger _logger;
private readonly IPurchaseLogic _purchase;
private readonly IBuildLogic _build;
public MainController(ILogger<MainController> logger, IPurchaseLogic pur, IBuildLogic build)
{
_logger = logger;
_purchase = pur;
_build = build;
}
[HttpPost]
public void CreateBuild(BuildBindingModel model)
{
try
{
_build.Create(model);
}
catch (Exception ex)
{
_logger.LogError(ex, "Ошибка создания");
throw;
}
}
[HttpPost]
public void CreatePurchase(PurchaseBindingModel model)
{
try
{
_purchase.Create(model);
}
catch (Exception ex)
{
_logger.LogError(ex, "Ошибка создания");
throw;
}
}
[HttpPut]
public void UpdateBuild(BuildBindingModel model)
{
try
{
_build.Update(model);
}
catch (Exception ex)
{
_logger.LogError(ex, "Ошибка обновления");
throw;
}
}
}
}