2023-05-15 22:33:12 +04:00
|
|
|
|
using HardwareShopBusinessLogic.BusinessLogics.Storekeeper;
|
|
|
|
|
using HardwareShopContracts.BindingModels;
|
2023-05-15 19:26:52 +04:00
|
|
|
|
using HardwareShopContracts.BusinessLogicsContracts;
|
|
|
|
|
using HardwareShopContracts.SearchModels;
|
|
|
|
|
using HardwareShopContracts.ViewModels;
|
2023-05-15 22:33:12 +04:00
|
|
|
|
using HardwareShopDatabaseImplement.Models.Worker;
|
|
|
|
|
using HardwareShopDataModels.Models;
|
2023-05-15 19:26:52 +04:00
|
|
|
|
using Microsoft.AspNetCore.Mvc;
|
2023-05-15 22:33:12 +04:00
|
|
|
|
using System.ComponentModel;
|
2023-05-15 19:26:52 +04:00
|
|
|
|
|
|
|
|
|
namespace HardwareShopRestApi.Controllers
|
|
|
|
|
{
|
|
|
|
|
[Route("api/[controller]/[action]")]
|
|
|
|
|
[ApiController]
|
2023-05-15 22:33:12 +04:00
|
|
|
|
public class BuildController : Controller
|
2023-05-15 19:26:52 +04:00
|
|
|
|
{
|
|
|
|
|
private readonly ILogger _logger;
|
2023-05-15 22:33:12 +04:00
|
|
|
|
private readonly IBuildLogic _buildLogic;
|
2023-05-15 19:26:52 +04:00
|
|
|
|
|
2023-05-16 12:48:47 +04:00
|
|
|
|
public BuildController(IBuildLogic buildLogic, ILogger<UserController> logger)
|
2023-05-15 19:26:52 +04:00
|
|
|
|
{
|
|
|
|
|
_logger = logger;
|
2023-05-15 22:33:12 +04:00
|
|
|
|
_buildLogic = buildLogic;
|
2023-05-15 19:26:52 +04:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[HttpGet]
|
2023-05-15 22:33:12 +04:00
|
|
|
|
public List<BuildViewModel>? GetBuilds(int userId)
|
2023-05-15 19:26:52 +04:00
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
2023-05-15 22:33:12 +04:00
|
|
|
|
return _buildLogic.ReadList(new BuildSearchModel
|
2023-05-15 19:26:52 +04:00
|
|
|
|
{
|
2023-05-15 22:33:12 +04:00
|
|
|
|
UserId = userId
|
2023-05-15 19:26:52 +04:00
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
2023-05-15 22:33:12 +04:00
|
|
|
|
_logger.LogError(ex, "Ошибка получения списка сборок");
|
|
|
|
|
throw;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[HttpGet]
|
2023-05-16 10:40:26 +04:00
|
|
|
|
public BuildViewModel? GetBuild(int buildId)
|
2023-05-15 22:33:12 +04:00
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
2023-05-16 10:40:26 +04:00
|
|
|
|
return _buildLogic.ReadElement(new() { Id = buildId });
|
2023-05-15 22:33:12 +04:00
|
|
|
|
}
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
|
|
|
|
_logger.LogError(ex, "Ошибка сборки");
|
2023-05-15 19:26:52 +04:00
|
|
|
|
throw;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[HttpPost]
|
2023-05-15 22:33:12 +04:00
|
|
|
|
public void Create(BuildBindingModel model)
|
2023-05-15 19:26:52 +04:00
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
2023-05-15 22:33:12 +04:00
|
|
|
|
_buildLogic.Create(model);
|
2023-05-15 19:26:52 +04:00
|
|
|
|
}
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
2023-05-15 22:33:12 +04:00
|
|
|
|
_logger.LogError(ex, "Ошибка сборки");
|
2023-05-15 19:26:52 +04:00
|
|
|
|
throw;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[HttpPost]
|
2023-05-15 22:33:12 +04:00
|
|
|
|
public void Update(BuildBindingModel model)
|
2023-05-15 19:26:52 +04:00
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
2023-05-15 22:33:12 +04:00
|
|
|
|
_buildLogic.Update(model);
|
2023-05-15 19:26:52 +04:00
|
|
|
|
}
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
|
|
|
|
_logger.LogError(ex, "Ошибка обновления данных");
|
|
|
|
|
throw;
|
|
|
|
|
}
|
|
|
|
|
}
|
2023-05-15 22:33:12 +04:00
|
|
|
|
|
|
|
|
|
[HttpPost]
|
2023-05-16 12:48:47 +04:00
|
|
|
|
public void DeleteBuild(BuildBindingModel model)
|
2023-05-15 22:33:12 +04:00
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
2023-05-16 12:48:47 +04:00
|
|
|
|
_buildLogic.Delete(model);
|
2023-05-15 22:33:12 +04:00
|
|
|
|
}
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
|
|
|
|
_logger.LogError(ex, "Ошибка удаления сборки");
|
|
|
|
|
throw;
|
|
|
|
|
}
|
|
|
|
|
}
|
2023-05-15 19:26:52 +04:00
|
|
|
|
}
|
|
|
|
|
}
|