2024-05-29 12:38:52 +04:00
|
|
|
|
using ComputerHardwareStoreContracts.BindingModels;
|
|
|
|
|
using ComputerHardwareStoreContracts.ViewModels;
|
|
|
|
|
using Microsoft.AspNetCore.Mvc;
|
|
|
|
|
using System.Xml.Linq;
|
|
|
|
|
|
|
|
|
|
namespace VendorClient.Controllers
|
|
|
|
|
{
|
2024-05-29 15:26:54 +04:00
|
|
|
|
[Route("Home/[action]")]
|
2024-05-29 12:38:52 +04:00
|
|
|
|
public class BuildController : Controller
|
|
|
|
|
{
|
|
|
|
|
private readonly ILogger _logger;
|
|
|
|
|
|
|
|
|
|
private const string API_ROUTE = "api/builds";
|
|
|
|
|
|
|
|
|
|
public BuildController(ILogger<BuildController> logger)
|
|
|
|
|
{
|
|
|
|
|
_logger = logger;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[HttpGet]
|
|
|
|
|
public IActionResult AddBuildToPurchase()
|
|
|
|
|
{
|
|
|
|
|
return View();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[HttpGet]
|
|
|
|
|
public IActionResult Builds()
|
|
|
|
|
{
|
|
|
|
|
if (APIClient.Vendor == null)
|
|
|
|
|
{
|
2024-05-29 15:26:54 +04:00
|
|
|
|
return Redirect("~/Home/Enter");
|
2024-05-29 12:38:52 +04:00
|
|
|
|
}
|
|
|
|
|
return View(APIClient.GetRequest<List<BuildViewModel>>($"{API_ROUTE}/getbuilds?userId={APIClient.Vendor.Id}"));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[HttpGet]
|
|
|
|
|
public void BuildCreate(string buildName)
|
|
|
|
|
{
|
|
|
|
|
if (APIClient.Vendor == null)
|
|
|
|
|
{
|
|
|
|
|
throw new Exception("Вы как суда попали? Суда вход только авторизованным");
|
|
|
|
|
}
|
|
|
|
|
if (string.IsNullOrEmpty(buildName))
|
|
|
|
|
{
|
|
|
|
|
throw new Exception($"Имя сборки не должно быть пустым");
|
|
|
|
|
}
|
|
|
|
|
APIClient.PostRequest($"{API_ROUTE}/create", new BuildBindingModel
|
|
|
|
|
{
|
|
|
|
|
Name = buildName,
|
|
|
|
|
VendorId = APIClient.Vendor.Id
|
|
|
|
|
});
|
2024-05-29 15:26:54 +04:00
|
|
|
|
Response.Redirect("~/Home/Builds");
|
2024-05-29 12:38:52 +04:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[HttpGet]
|
|
|
|
|
public void BuildDelete(int id)
|
|
|
|
|
{
|
|
|
|
|
if (APIClient.Vendor == null)
|
|
|
|
|
{
|
|
|
|
|
throw new Exception("Вы как суда попали? Суда вход только авторизованным");
|
|
|
|
|
}
|
|
|
|
|
if (id <= 0)
|
|
|
|
|
{
|
|
|
|
|
throw new Exception($"Идентификатор сборки не может быть ниже или равен 0");
|
|
|
|
|
}
|
|
|
|
|
APIClient.PostRequest("api/build/DeleteBuild", new BuildBindingModel
|
|
|
|
|
{
|
|
|
|
|
Id = id
|
|
|
|
|
});
|
2024-05-29 15:26:54 +04:00
|
|
|
|
Response.Redirect("~/Home/Builds");
|
2024-05-29 12:38:52 +04:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[HttpGet]
|
|
|
|
|
public void BuildUpdate(string buildName, int buildId)
|
|
|
|
|
{
|
|
|
|
|
if (APIClient.Vendor == null)
|
|
|
|
|
{
|
|
|
|
|
throw new Exception("Вы как суда попали? Суда вход только авторизованным");
|
|
|
|
|
}
|
|
|
|
|
if (string.IsNullOrEmpty(buildName))
|
|
|
|
|
{
|
|
|
|
|
throw new Exception($"Имя сборки не должно быть пустым");
|
|
|
|
|
}
|
|
|
|
|
if (buildId <= 0)
|
|
|
|
|
{
|
|
|
|
|
throw new Exception($"Идентификатор сборки не может быть ниже или равен 0");
|
|
|
|
|
}
|
|
|
|
|
APIClient.PostRequest($"{API_ROUTE}/update", new BuildBindingModel
|
|
|
|
|
{
|
|
|
|
|
Id = buildId,
|
|
|
|
|
Name = buildName
|
|
|
|
|
});
|
2024-05-29 15:26:54 +04:00
|
|
|
|
Response.Redirect("~/Home/Builds");
|
2024-05-29 12:38:52 +04:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|