2023-04-07 18:59:41 +04:00
|
|
|
|
using ComputerShopClientApp.Models;
|
|
|
|
|
using ComputerShopContracts.BindingModels;
|
|
|
|
|
using ComputerShopContracts.ViewModels;
|
|
|
|
|
using Microsoft.AspNetCore.Mvc;
|
|
|
|
|
using System.Diagnostics;
|
|
|
|
|
|
|
|
|
|
namespace ComputerShopClientApp.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");
|
|
|
|
|
}
|
|
|
|
|
return View(APIClient.GetRequest<List<PurchaseViewModel>>($"api/main/getpurchases?clientId={APIClient.Client.Id}"));
|
|
|
|
|
}
|
|
|
|
|
|
2023-04-08 13:46:24 +04:00
|
|
|
|
public IActionResult Component()
|
|
|
|
|
{
|
|
|
|
|
if (APIClient.Client == null)
|
|
|
|
|
{
|
|
|
|
|
return Redirect("~/Home/Enter");
|
|
|
|
|
}
|
|
|
|
|
return View(APIClient.GetRequest<List<ComponentViewModel>>($"api/component/getcomponentlist"));
|
|
|
|
|
}
|
2023-04-09 11:30:54 +04:00
|
|
|
|
public IActionResult Assembly()
|
|
|
|
|
{
|
|
|
|
|
if (APIClient.Client == null)
|
|
|
|
|
{
|
|
|
|
|
return Redirect("~/Home/Enter");
|
|
|
|
|
}
|
|
|
|
|
return View(APIClient.GetRequest<List<AssemblyViewModel>>($"api/assembly/getassemblylist"));
|
|
|
|
|
}
|
2023-04-08 13:46:24 +04:00
|
|
|
|
|
2023-04-07 18:59:41 +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-04-08 13:46:24 +04:00
|
|
|
|
public IActionResult CreatePurchase()
|
2023-04-07 18:59:41 +04:00
|
|
|
|
{
|
|
|
|
|
ViewBag.Components = APIClient.GetRequest<List<ComponentViewModel>>("api/main/getcomponentlist");
|
|
|
|
|
return View();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[HttpPost]
|
2023-04-08 13:46:24 +04:00
|
|
|
|
public void CreatePurchase(int component, int count)
|
2023-04-07 18:59:41 +04:00
|
|
|
|
{
|
|
|
|
|
if (APIClient.Client == null)
|
|
|
|
|
{
|
|
|
|
|
throw new Exception("Вы как суда попали? Суда вход только авторизованным");
|
|
|
|
|
}
|
|
|
|
|
if (count <= 0)
|
|
|
|
|
{
|
|
|
|
|
throw new Exception("Количество и сумма должны быть больше 0");
|
|
|
|
|
}
|
|
|
|
|
APIClient.PostRequest("api/main/createpurchase", new PurchaseBindingModel
|
|
|
|
|
{
|
|
|
|
|
ClientId = APIClient.Client.Id,
|
|
|
|
|
ComponentId = component,
|
|
|
|
|
Count = count,
|
|
|
|
|
Sum = Calc(count, component)
|
|
|
|
|
});
|
|
|
|
|
Response.Redirect("Index");
|
|
|
|
|
}
|
|
|
|
|
|
2023-04-08 13:46:24 +04:00
|
|
|
|
[HttpGet]
|
|
|
|
|
public IActionResult CreateComponent()
|
|
|
|
|
{
|
|
|
|
|
return View();
|
|
|
|
|
}
|
|
|
|
|
[HttpPost]
|
|
|
|
|
public void CreateComponent(string name, int cost)
|
|
|
|
|
{
|
|
|
|
|
if (APIClient.Client == null)
|
|
|
|
|
{
|
|
|
|
|
throw new Exception("Вы как суда попали? Суда вход только авторизованным");
|
|
|
|
|
}
|
|
|
|
|
if (cost <= 0)
|
|
|
|
|
{
|
|
|
|
|
throw new Exception("Цена должна быть больше 0");
|
|
|
|
|
}
|
|
|
|
|
APIClient.PostRequest("api/component/createcomponent", new ComponentBindingModel
|
|
|
|
|
{
|
|
|
|
|
ClientId = APIClient.Client.Id,
|
|
|
|
|
ComponentName = name,
|
|
|
|
|
Cost = cost
|
|
|
|
|
});
|
|
|
|
|
Response.Redirect("Index");
|
|
|
|
|
}
|
|
|
|
|
|
2023-04-09 11:30:54 +04:00
|
|
|
|
[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");
|
|
|
|
|
}
|
|
|
|
|
//APIClient.PostRequest("api/assembly/createassembly", new AssemblyBindingModel
|
|
|
|
|
//{
|
|
|
|
|
// ClientId = APIClient.Client.Id,
|
|
|
|
|
// AssemblyName = name,
|
|
|
|
|
// Price = 0,
|
|
|
|
|
// AssemblyComponents = new()
|
|
|
|
|
//});
|
|
|
|
|
System.Diagnostics.Debug.WriteLine("it might work");
|
|
|
|
|
Response.Redirect("Index");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2023-04-08 13:46:24 +04:00
|
|
|
|
|
2023-04-07 18:59:41 +04:00
|
|
|
|
[HttpPost]
|
|
|
|
|
public double Calc(int count, int component)
|
|
|
|
|
{
|
|
|
|
|
var comp = APIClient.GetRequest<ComponentViewModel>($"api/main/getcomponent?componentId={component}");
|
|
|
|
|
return count * (comp?.Cost ?? 1);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|