Computer_Hardware_Store/HardwareShop/HardwareShopRestApi/Controllers/BuildController.cs

116 lines
3.1 KiB
C#

using HardwareShopBusinessLogic.BusinessLogics.Storekeeper;
using HardwareShopContracts.BindingModels;
using HardwareShopContracts.BusinessLogicsContracts;
using HardwareShopContracts.SearchModels;
using HardwareShopContracts.ViewModels;
using HardwareShopDatabaseImplement.Models.Worker;
using HardwareShopDataModels.Models;
using Microsoft.AspNetCore.Mvc;
using System.ComponentModel;
namespace HardwareShopRestApi.Controllers
{
[Route("api/[controller]/[action]")]
[ApiController]
public class BuildController : Controller
{
private readonly ILogger _logger;
private readonly IBuildLogic _buildLogic;
private readonly IComponentLogic _componentLogic;
public BuildController(IBuildLogic buildLogic, IComponentLogic componentLogic, ILogger<UserController> logger)
{
_logger = logger;
_buildLogic = buildLogic;
_componentLogic = componentLogic;
}
[HttpGet]
public List<BuildViewModel>? GetBuilds(int userId)
{
try
{
return _buildLogic.ReadList(new BuildSearchModel
{
UserId = userId
});
}
catch (Exception ex)
{
_logger.LogError(ex, "Ошибка получения списка сборок");
throw;
}
}
[HttpGet]
public BuildViewModel? GetBuild(int buildId)
{
try
{
return _buildLogic.ReadElement(new() { Id = buildId });
}
catch (Exception ex)
{
_logger.LogError(ex, "Ошибка сборки");
throw;
}
}
[HttpPost]
public void Create(BuildBindingModel model)
{
try
{
_buildLogic.Create(model);
}
catch (Exception ex)
{
_logger.LogError(ex, "Ошибка сборки");
throw;
}
}
[HttpPost]
public void Update(BuildBindingModel model)
{
try
{
_buildLogic.Update(model);
}
catch (Exception ex)
{
_logger.LogError(ex, "Ошибка обновления данных");
throw;
}
}
[HttpPost]
public void DeleteShop(BuildBindingModel model)
{
try
{
_buildLogic.Update(model);
}
catch (Exception ex)
{
_logger.LogError(ex, "Ошибка удаления сборки");
throw;
}
}
[HttpPost]
public void AddDishInShop(ComponentBindingModel model)
{
try
{
_componentLogic.Update(model);
}
catch (Exception ex)
{
_logger.LogError(ex, "Ошибка компонента в сборку");
throw;
}
}
}
}