CourseWork_CompShop/ComputerShopProvider/OrdererClientApp/Controllers/HomeController.cs

250 lines
7.9 KiB
C#
Raw Normal View History

2023-05-17 14:20:02 +04:00
using ComputerShopContracts.BindingModels;
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)
{
return Redirect("~/Home/Enter");
}
2023-12-01 19:59:06 +04:00
return View(APIClient.GetRequest<List<OrderViewModel>>($"api/component/order"));
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;
}
[HttpGet]
2023-12-01 19:59:06 +04:00
public IActionResult CreateReceiving()
{
if (APIClient.Client == null)
{
throw new Exception("Вы как суда попали? Суда вход только авторизованным");
}
APIClient.PostRequest("api/equipmentreceiving/createreceiving", new EquipmentReceivingBindingModel
{
ClientId = APIClient.Client.Id
});
Response.Redirect("Index");
return View();
}
[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");
}
[HttpGet]
public IActionResult CreateAssembly()
{
ViewBag.Components = APIClient.GetRequest<List<ComponentViewModel>>("api/component/getcomponentlist");
ViewBag.CurrentComponents = new List<ComponentViewModel>();
return View();
}
[HttpPost]
public void CreateAssembly(string name, int sum)
{
if (APIClient.Client == null)
{
throw new Exception("Вы как суда попали? Суда вход только авторизованным");
}
if (sum <= 0)
{
throw new Exception("Сумма должна быть больше 0");
}
2023-05-20 09:23:37 +04:00
APIClient.PostRequest("api/assembly/createassembly", new AssemblyBindingModel
{
ClientId = APIClient.Client.Id,
AssemblyName = name,
Price = 0,
AssemblyComponents = new()
});
2023-05-17 14:20:02 +04:00
System.Diagnostics.Debug.WriteLine("it might work");
Response.Redirect("Index");
}
[HttpPost]
2023-05-20 09:50:02 +04:00
public double Calc(int count, int order)
2023-05-17 14:20:02 +04:00
{
2023-05-20 09:50:02 +04:00
var or = APIClient.GetRequest<OrderViewModel>($"api/main/getcomponent?componentId={order}");
return count * (or?.Sum ?? 1);
2023-05-17 14:20:02 +04:00
}
}
}