2023-05-17 14:20:02 +04:00
|
|
|
|
using ComputerShopContracts.BindingModels;
|
2023-12-02 01:30:33 +04:00
|
|
|
|
using ComputerShopContracts.SearchModels;
|
2023-05-17 14:20:02 +04:00
|
|
|
|
using ComputerShopContracts.ViewModels;
|
2023-12-01 19:59:06 +04:00
|
|
|
|
using DocumentFormat.OpenXml.Office2010.Excel;
|
2023-05-17 14:20:02 +04:00
|
|
|
|
using Microsoft.AspNetCore.Mvc;
|
|
|
|
|
using OrdererClientApp.Models;
|
2023-12-01 19:59:06 +04:00
|
|
|
|
using System.ComponentModel;
|
2023-05-17 14:20:02 +04:00
|
|
|
|
using System.Diagnostics;
|
|
|
|
|
|
|
|
|
|
namespace OrdererClientApp.Controllers
|
|
|
|
|
{
|
|
|
|
|
public class HomeController : Controller
|
|
|
|
|
{
|
|
|
|
|
private readonly ILogger<HomeController> _logger;
|
|
|
|
|
|
|
|
|
|
public HomeController(ILogger<HomeController> logger)
|
|
|
|
|
{
|
|
|
|
|
_logger = logger;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public IActionResult Index()
|
|
|
|
|
{
|
|
|
|
|
if (APIClient.Client == null)
|
|
|
|
|
{
|
|
|
|
|
return Redirect("~/Home/Enter");
|
|
|
|
|
}
|
2023-12-01 19:59:06 +04:00
|
|
|
|
return View(APIClient.GetRequest<List<EquipmentReceivingViewModel>>($"api/equipmentreceiving/getreceivings?clientId={APIClient.Client.Id}"));
|
2023-05-17 14:20:02 +04:00
|
|
|
|
}
|
|
|
|
|
|
2023-12-01 19:59:06 +04:00
|
|
|
|
public IActionResult Order()
|
2023-05-17 14:20:02 +04:00
|
|
|
|
{
|
|
|
|
|
if (APIClient.Client == null)
|
|
|
|
|
{
|
2023-12-02 01:30:33 +04:00
|
|
|
|
return Redirect("~/Order/Enter");
|
2023-05-17 14:20:02 +04:00
|
|
|
|
}
|
2023-12-02 01:30:33 +04:00
|
|
|
|
return View(APIClient.GetRequest<List<OrderViewModel>>($"api/order/getorderlist?clientId={APIClient.Client.Id}"));
|
2023-05-17 14:20:02 +04:00
|
|
|
|
}
|
2023-05-20 09:50:02 +04:00
|
|
|
|
public IActionResult Supply()
|
2023-05-17 14:20:02 +04:00
|
|
|
|
{
|
|
|
|
|
if (APIClient.Client == null)
|
|
|
|
|
{
|
|
|
|
|
return Redirect("~/Home/Enter");
|
|
|
|
|
}
|
2023-12-01 19:59:06 +04:00
|
|
|
|
return View(APIClient.GetRequest<List<SupplyViewModel>>($"api/supply/getsupplylist"));
|
2023-05-17 14:20:02 +04:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[HttpGet]
|
|
|
|
|
public IActionResult Privacy()
|
|
|
|
|
{
|
|
|
|
|
if (APIClient.Client == null)
|
|
|
|
|
{
|
|
|
|
|
return Redirect("~/Home/Enter");
|
|
|
|
|
}
|
|
|
|
|
return View(APIClient.Client);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[HttpPost]
|
|
|
|
|
public void Privacy(string login, string password, string fio)
|
|
|
|
|
{
|
|
|
|
|
if (APIClient.Client == null)
|
|
|
|
|
{
|
|
|
|
|
throw new Exception("Вы как суда попали? Суда вход только авторизованным");
|
|
|
|
|
}
|
|
|
|
|
if (string.IsNullOrEmpty(login) || string.IsNullOrEmpty(password) || string.IsNullOrEmpty(fio))
|
|
|
|
|
{
|
|
|
|
|
throw new Exception("Введите логин, пароль и ФИО");
|
|
|
|
|
}
|
|
|
|
|
APIClient.PostRequest("api/client/updatedata", new ClientBindingModel
|
|
|
|
|
{
|
|
|
|
|
Id = APIClient.Client.Id,
|
|
|
|
|
ClientFIO = fio,
|
|
|
|
|
Email = login,
|
|
|
|
|
Password = password
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
APIClient.Client.ClientFIO = fio;
|
|
|
|
|
APIClient.Client.Email = login;
|
|
|
|
|
APIClient.Client.Password = password;
|
|
|
|
|
Response.Redirect("Index");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[ResponseCache(Duration = 0, Location = ResponseCacheLocation.None, NoStore = true)]
|
|
|
|
|
public IActionResult Error()
|
|
|
|
|
{
|
|
|
|
|
return View(new ErrorViewModel { RequestId = Activity.Current?.Id ?? HttpContext.TraceIdentifier });
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[HttpGet]
|
|
|
|
|
public IActionResult Enter()
|
|
|
|
|
{
|
|
|
|
|
return View();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[HttpPost]
|
|
|
|
|
public void Enter(string login, string password)
|
|
|
|
|
{
|
|
|
|
|
if (string.IsNullOrEmpty(login) || string.IsNullOrEmpty(password))
|
|
|
|
|
{
|
|
|
|
|
throw new Exception("Введите логин и пароль");
|
|
|
|
|
}
|
|
|
|
|
APIClient.Client = APIClient.GetRequest<ClientViewModel>($"api/client/login?login={login}&password={password}");
|
|
|
|
|
if (APIClient.Client == null)
|
|
|
|
|
{
|
|
|
|
|
throw new Exception("Неверный логин/пароль");
|
|
|
|
|
}
|
|
|
|
|
Response.Redirect("Index");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[HttpGet]
|
|
|
|
|
public IActionResult Register()
|
|
|
|
|
{
|
|
|
|
|
return View();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[HttpPost]
|
|
|
|
|
public void Register(string login, string password, string fio)
|
|
|
|
|
{
|
|
|
|
|
if (string.IsNullOrEmpty(login) || string.IsNullOrEmpty(password) || string.IsNullOrEmpty(fio))
|
|
|
|
|
{
|
|
|
|
|
throw new Exception("Введите логин, пароль и ФИО");
|
|
|
|
|
}
|
|
|
|
|
APIClient.PostRequest("api/client/register", new ClientBindingModel
|
|
|
|
|
{
|
|
|
|
|
ClientFIO = fio,
|
|
|
|
|
Email = login,
|
|
|
|
|
Password = password
|
|
|
|
|
});
|
|
|
|
|
Response.Redirect("Enter");
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2023-12-02 01:30:33 +04:00
|
|
|
|
[HttpPost]
|
|
|
|
|
public void CreateReceiving()
|
2023-12-01 19:59:06 +04:00
|
|
|
|
|
|
|
|
|
{
|
|
|
|
|
if (APIClient.Client == null)
|
|
|
|
|
{
|
|
|
|
|
throw new Exception("Вы как суда попали? Суда вход только авторизованным");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
APIClient.PostRequest("api/equipmentreceiving/createreceiving", new EquipmentReceivingBindingModel
|
|
|
|
|
{
|
|
|
|
|
ClientId = APIClient.Client.Id
|
|
|
|
|
});
|
|
|
|
|
Response.Redirect("Index");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[HttpPost]
|
|
|
|
|
public void SetFinish(int id)
|
|
|
|
|
{
|
|
|
|
|
if (APIClient.Client == null)
|
|
|
|
|
{
|
|
|
|
|
throw new Exception("Вы как суда попали? Суда вход только авторизованным");
|
|
|
|
|
}
|
|
|
|
|
APIClient.PostRequest($"api/equipmentreceiving/setfinish?id={id}", id);
|
|
|
|
|
Response.Redirect("Index");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[HttpPost]
|
|
|
|
|
public void DeleteReceiving(int receiving)
|
|
|
|
|
{
|
|
|
|
|
if (APIClient.Client == null)
|
|
|
|
|
{
|
|
|
|
|
throw new Exception("Вы как суда попали? Суда вход только авторизованным");
|
|
|
|
|
}
|
|
|
|
|
APIClient.PostRequest($"api/equipmentreceiving/deletereceiving?id={receiving}", receiving);
|
|
|
|
|
Response.Redirect("Index");
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[HttpGet]
|
2023-05-20 09:23:37 +04:00
|
|
|
|
public IActionResult CreateOrder()
|
2023-05-17 14:20:02 +04:00
|
|
|
|
{
|
|
|
|
|
return View();
|
|
|
|
|
}
|
|
|
|
|
[HttpPost]
|
2023-05-20 09:23:37 +04:00
|
|
|
|
public void CreateOrder(int sum)
|
2023-05-17 14:20:02 +04:00
|
|
|
|
{
|
|
|
|
|
if (APIClient.Client == null)
|
|
|
|
|
{
|
|
|
|
|
throw new Exception("Вы как суда попали? Суда вход только авторизованным");
|
|
|
|
|
}
|
2023-05-20 09:23:37 +04:00
|
|
|
|
APIClient.PostRequest("api/order/createorder", new OrderBindingModel
|
2023-05-17 14:20:02 +04:00
|
|
|
|
{
|
|
|
|
|
ClientId = APIClient.Client.Id,
|
2023-05-20 09:50:02 +04:00
|
|
|
|
Sum = sum
|
2023-05-17 14:20:02 +04:00
|
|
|
|
});
|
|
|
|
|
Response.Redirect("Index");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[HttpGet]
|
2023-05-20 09:50:02 +04:00
|
|
|
|
public IActionResult DeleteOrder()
|
2023-05-17 14:20:02 +04:00
|
|
|
|
{
|
2023-05-20 09:50:02 +04:00
|
|
|
|
ViewBag.Components = APIClient.GetRequest<List<ComponentViewModel>>("api/main/getorderlist");
|
2023-05-17 14:20:02 +04:00
|
|
|
|
return View();
|
|
|
|
|
}
|
|
|
|
|
[HttpDelete]
|
2023-05-20 09:50:02 +04:00
|
|
|
|
public void DeleteOrder(int order)
|
2023-05-17 14:20:02 +04:00
|
|
|
|
{
|
|
|
|
|
if (APIClient.Client == null)
|
|
|
|
|
{
|
|
|
|
|
throw new Exception("Вы как суда попали? Суда вход только авторизованным");
|
|
|
|
|
}
|
2023-12-01 19:59:06 +04:00
|
|
|
|
APIClient.PostRequest("api/order/deleteorder", new ComponentBindingModel
|
2023-05-17 14:20:02 +04:00
|
|
|
|
{
|
2023-05-20 09:50:02 +04:00
|
|
|
|
Id = order
|
2023-05-17 14:20:02 +04:00
|
|
|
|
});
|
|
|
|
|
Response.Redirect("Index");
|
|
|
|
|
}
|
|
|
|
|
|
2023-12-02 01:30:33 +04:00
|
|
|
|
public IActionResult AddAssemblyToOrder()
|
|
|
|
|
{
|
|
|
|
|
if (APIClient.Client == null)
|
|
|
|
|
{
|
|
|
|
|
return Redirect("~/Home/Enter");
|
|
|
|
|
}
|
|
|
|
|
ViewBag.Assemblies = APIClient.GetRequest<List<OrderViewModel>>($"api/order/getorderlist?clientId={APIClient.Client.Id}");
|
|
|
|
|
ViewBag.Components = APIClient.GetRequest<List<AssemblyViewModel>>($"api/assembly/getassemblylist?clientId={APIClient.Client.Id}");
|
|
|
|
|
return View();
|
|
|
|
|
}
|
2023-05-17 14:20:02 +04:00
|
|
|
|
|
2023-12-02 01:30:33 +04:00
|
|
|
|
[HttpPost]
|
2023-12-02 01:39:39 +04:00
|
|
|
|
public void AddAssembly(int order, int assembly, int amount)
|
2023-12-02 01:30:33 +04:00
|
|
|
|
{
|
|
|
|
|
if (APIClient.Client == null)
|
|
|
|
|
{
|
|
|
|
|
throw new Exception("Необходима авторизация");
|
|
|
|
|
}
|
2023-12-02 01:39:39 +04:00
|
|
|
|
APIClient.PostRequest("api/order/AddAssembly", Tuple.Create(
|
2023-12-02 01:30:33 +04:00
|
|
|
|
new AssemblySearchModel() { Id = assembly },
|
|
|
|
|
new OrderSearchModel() { Id = order },
|
|
|
|
|
|
|
|
|
|
amount
|
|
|
|
|
));
|
2023-05-17 14:20:02 +04:00
|
|
|
|
|
2023-12-02 01:30:33 +04:00
|
|
|
|
}
|
2023-05-17 14:20:02 +04:00
|
|
|
|
|
2023-12-02 01:30:33 +04:00
|
|
|
|
[HttpPost]
|
|
|
|
|
public double Calc(int count, int assembly)
|
2023-05-17 14:20:02 +04:00
|
|
|
|
{
|
2023-12-02 01:30:33 +04:00
|
|
|
|
var or = APIClient.GetRequest<OrderViewModel>($"api/main/getassembly?assemblyId={assembly}");
|
2023-05-20 09:50:02 +04:00
|
|
|
|
return count * (or?.Sum ?? 1);
|
2023-05-17 14:20:02 +04:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|