2023-04-09 11:30:54 +04:00
|
|
|
|
using ComputerShopContracts.BindingModels;
|
|
|
|
|
using ComputerShopContracts.BusinessLogicContracts;
|
2023-05-17 12:19:00 +04:00
|
|
|
|
using ComputerShopContracts.SearchModels;
|
2023-04-09 11:30:54 +04:00
|
|
|
|
using ComputerShopContracts.ViewModels;
|
2023-05-17 13:52:06 +04:00
|
|
|
|
using ComputerShopDataModels.Models;
|
2023-04-09 11:30:54 +04:00
|
|
|
|
using Microsoft.AspNetCore.Mvc;
|
|
|
|
|
|
|
|
|
|
namespace ComputerShopRestApi.Controllers
|
|
|
|
|
{
|
|
|
|
|
[Route("api/[controller]/[action]")]
|
|
|
|
|
[ApiController]
|
|
|
|
|
public class AssemblyController : Controller
|
|
|
|
|
{
|
|
|
|
|
private readonly ILogger _logger;
|
|
|
|
|
private readonly IAssemblyLogic _assembly;
|
|
|
|
|
private readonly IComponentLogic _component;
|
|
|
|
|
public AssemblyController(ILogger<AssemblyController> logger, IAssemblyLogic assembly, IComponentLogic component)
|
|
|
|
|
{
|
|
|
|
|
_logger = logger;
|
|
|
|
|
_assembly = assembly;
|
|
|
|
|
_component = component;
|
|
|
|
|
}
|
|
|
|
|
[HttpGet]
|
2023-05-17 12:19:00 +04:00
|
|
|
|
public List<AssemblyViewModel>? GetAssemblyList(int clientId)
|
2023-04-09 11:30:54 +04:00
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
2023-05-17 12:19:00 +04:00
|
|
|
|
return _assembly.ReadList(new AssemblySearchModel
|
|
|
|
|
{
|
|
|
|
|
ClientId = clientId,
|
|
|
|
|
});
|
2023-04-09 11:30:54 +04:00
|
|
|
|
}
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
|
|
|
|
_logger.LogError(ex, "Ошибка получения списка сборок");
|
|
|
|
|
throw;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
[HttpGet]
|
|
|
|
|
public List<ComponentViewModel>? GetComponentList()
|
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
return _component.ReadList(null);
|
|
|
|
|
}
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
|
|
|
|
_logger.LogError(ex, "Ошибка получения списка компонентов");
|
|
|
|
|
throw;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
[HttpPost]
|
|
|
|
|
public void CreateAssembly(AssemblyBindingModel model)
|
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
_assembly.Create(model);
|
|
|
|
|
}
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
|
|
|
|
_logger.LogError(ex, "Ошибка создания сборки");
|
|
|
|
|
throw;
|
|
|
|
|
}
|
|
|
|
|
}
|
2023-05-17 12:19:00 +04:00
|
|
|
|
[HttpPost]
|
|
|
|
|
public void DeleteAssembly(AssemblyBindingModel model)
|
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
_assembly.Delete(model);
|
|
|
|
|
}
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
|
|
|
|
_logger.LogError(ex, "Ошибка удаления сборки");
|
|
|
|
|
throw;
|
|
|
|
|
}
|
|
|
|
|
}
|
2023-05-17 13:52:06 +04:00
|
|
|
|
|
|
|
|
|
[HttpPost]
|
|
|
|
|
public void AddComponentToAssembly(Tuple<AssemblySearchModel, ComponentSearchModel, int> model)
|
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
_assembly.AddComponentToAssembly(model.Item1, model.Item2, model.Item3);
|
|
|
|
|
}
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
|
|
|
|
_logger.LogError(ex, "Ошибка добавления компонента в сборку.");
|
|
|
|
|
throw;
|
|
|
|
|
}
|
|
|
|
|
}
|
2023-04-09 11:30:54 +04:00
|
|
|
|
}
|
|
|
|
|
}
|