2024-05-25 17:47:14 +04:00
|
|
|
|
using ElectronicsShopContracts.BindingModels;
|
2024-05-29 23:03:32 +04:00
|
|
|
|
using ElectronicsShopContracts.BusinessLogicContracts;
|
2024-05-29 18:32:24 +04:00
|
|
|
|
using ElectronicsShopContracts.SearchModels;
|
2024-05-25 17:47:14 +04:00
|
|
|
|
using ElectronicsShopContracts.ViewModels;
|
2024-05-29 15:31:22 +04:00
|
|
|
|
using ElectronicsShopDataModels.Models;
|
2024-05-25 17:47:14 +04:00
|
|
|
|
using ElectronicsShopUserApp.Models;
|
|
|
|
|
using Microsoft.AspNetCore.Mvc;
|
|
|
|
|
using System.Diagnostics;
|
2024-05-29 23:03:32 +04:00
|
|
|
|
using System.Reflection;
|
2024-05-25 17:47:14 +04:00
|
|
|
|
using System.Runtime.Serialization;
|
|
|
|
|
|
|
|
|
|
namespace ElectronicsShopUserApp.Controllers {
|
|
|
|
|
public class HomeController : Controller {
|
|
|
|
|
private readonly ILogger<HomeController> _logger;
|
2024-05-29 23:03:32 +04:00
|
|
|
|
//private readonly IOrderLogic _order;
|
2024-05-25 17:47:14 +04:00
|
|
|
|
|
2024-05-29 23:03:32 +04:00
|
|
|
|
public HomeController(ILogger<HomeController> logger/*, IOrderLogic orderLogic*/) {
|
2024-05-25 17:47:14 +04:00
|
|
|
|
_logger = logger;
|
2024-05-29 23:03:32 +04:00
|
|
|
|
//_order = orderLogic;
|
2024-05-25 17:47:14 +04:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public IActionResult Index() {
|
|
|
|
|
if (APIClient.Client == null) {
|
|
|
|
|
return Redirect("~/Home/Enter");
|
|
|
|
|
}
|
|
|
|
|
return View(APIClient.GetRequset<List<OrderViewModel>>($"api/main/getorders?_clientid={APIClient.Client.ID}"));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[HttpGet]
|
|
|
|
|
public IActionResult Privacy() {
|
|
|
|
|
if (APIClient.Client == null) {
|
|
|
|
|
return Redirect("~/home/Enter");
|
|
|
|
|
}
|
|
|
|
|
return View(APIClient.Client);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[HttpPost]
|
|
|
|
|
public void Privacy(string email, string password, string fio) {
|
|
|
|
|
if (APIClient.Client == null) {
|
|
|
|
|
throw new Exception("<22><><EFBFBD><EFBFBD> <20><><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>");
|
|
|
|
|
}
|
|
|
|
|
if (string.IsNullOrEmpty(email) || string.IsNullOrEmpty(password) || string.IsNullOrEmpty(fio)) {
|
|
|
|
|
throw new Exception("<22><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD>, <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20> <20><><EFBFBD>");
|
|
|
|
|
}
|
|
|
|
|
APIClient.PostRequest("api/client/updatedata", new ClientBindingModel {
|
|
|
|
|
ID = APIClient.Client.ID,
|
|
|
|
|
ClientFIO = fio,
|
|
|
|
|
Email = email,
|
|
|
|
|
Password = password,
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
APIClient.Client.ClientFIO = fio;
|
|
|
|
|
APIClient.Client.Email = email;
|
|
|
|
|
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 email, string password) {
|
|
|
|
|
if (string.IsNullOrEmpty(email) || string.IsNullOrEmpty(password)) {
|
|
|
|
|
throw new Exception("<22><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD> <20> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>");
|
|
|
|
|
}
|
2024-05-27 19:12:19 +04:00
|
|
|
|
APIClient.Client = APIClient.GetRequset<ClientViewModel>($"api/Client/Login?email={email}&password={password}");
|
2024-05-25 17:47:14 +04:00
|
|
|
|
if (APIClient.Client == null) {
|
|
|
|
|
throw new Exception("<22><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD>/<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>");
|
|
|
|
|
}
|
|
|
|
|
Response.Redirect("Index");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[HttpGet]
|
|
|
|
|
public IActionResult Register() {
|
|
|
|
|
return View();
|
|
|
|
|
}
|
2024-05-29 15:31:22 +04:00
|
|
|
|
[HttpPost]
|
2024-05-25 17:47:14 +04:00
|
|
|
|
public void Register(string email, string password, string fio) {
|
|
|
|
|
if (string.IsNullOrEmpty(email) || string.IsNullOrEmpty(password) || string.IsNullOrEmpty(fio)) {
|
|
|
|
|
throw new Exception("<22><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD>,<2C><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20> <20><><EFBFBD>");
|
|
|
|
|
}
|
|
|
|
|
APIClient.PostRequest("api/client/register", new ClientBindingModel {
|
|
|
|
|
ClientFIO = fio,
|
|
|
|
|
Email = email,
|
|
|
|
|
Password = password
|
|
|
|
|
});
|
|
|
|
|
Response.Redirect("Enter");
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[HttpGet]
|
2024-05-29 23:03:32 +04:00
|
|
|
|
public IActionResult CreateOrders() {
|
|
|
|
|
|
|
|
|
|
ViewBag.Products =APIClient.GetRequset<List<ProductViewModel>>("api/main/getproducts");
|
2024-05-25 17:47:14 +04:00
|
|
|
|
return View();
|
|
|
|
|
}
|
2024-05-29 15:31:22 +04:00
|
|
|
|
[HttpPost]
|
2024-05-29 23:03:32 +04:00
|
|
|
|
public void CreateOrders(OrderBindingModel order) {
|
2024-05-29 15:31:22 +04:00
|
|
|
|
if (APIClient.Client == null)
|
|
|
|
|
{
|
|
|
|
|
throw new Exception("<22><> <20><><EFBFBD> <20><><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>? <20><><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>");
|
|
|
|
|
}
|
2024-05-29 18:32:24 +04:00
|
|
|
|
if (order.ProductList.Count > 0)
|
2024-05-29 15:31:22 +04:00
|
|
|
|
{
|
|
|
|
|
throw new Exception("<22><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20> <20><><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> 0");
|
|
|
|
|
}
|
2024-05-29 21:23:34 +04:00
|
|
|
|
Response.Redirect("Index");
|
2024-05-29 15:31:22 +04:00
|
|
|
|
}
|
|
|
|
|
[HttpPost]
|
2024-05-29 18:32:24 +04:00
|
|
|
|
private double CalcAll(Dictionary<int, (IProductModel, int)> ProductList)
|
2024-05-29 15:31:22 +04:00
|
|
|
|
{
|
|
|
|
|
Double Sum = 0;
|
|
|
|
|
foreach (var ProductItem in ProductList)
|
|
|
|
|
{
|
|
|
|
|
Sum += (ProductItem.Value.Item1.Price * ProductItem.Value.Item2);
|
|
|
|
|
}
|
|
|
|
|
return Sum;
|
|
|
|
|
}
|
2024-05-29 18:32:24 +04:00
|
|
|
|
[HttpPost]
|
2024-05-29 21:23:34 +04:00
|
|
|
|
public double Calc(int count, int product)
|
2024-05-29 18:32:24 +04:00
|
|
|
|
{
|
|
|
|
|
var prod =
|
2024-05-29 23:03:32 +04:00
|
|
|
|
APIClient.GetRequset<ProductViewModel>($"api/main/getproduct?_productid={product}"
|
2024-05-29 18:32:24 +04:00
|
|
|
|
);
|
|
|
|
|
return count * (prod?.Price ?? 1);
|
|
|
|
|
}
|
|
|
|
|
[HttpGet]
|
|
|
|
|
public IActionResult AddProduct()
|
|
|
|
|
{
|
|
|
|
|
ViewBag.Products = APIClient.GetRequset<List<ProductViewModel>>("api/main/getproducts");
|
|
|
|
|
return View();
|
|
|
|
|
}
|
|
|
|
|
[HttpPost]
|
2024-05-29 23:03:32 +04:00
|
|
|
|
public void AddProduct(int count/*, int product*/)
|
2024-05-29 18:32:24 +04:00
|
|
|
|
{
|
|
|
|
|
if (APIClient.Client == null)
|
|
|
|
|
{
|
|
|
|
|
throw new Exception("<22><> <20><><EFBFBD> <20><><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>? <20><><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>");
|
|
|
|
|
}
|
|
|
|
|
if (count <= 0)
|
|
|
|
|
{
|
|
|
|
|
throw new Exception("<22><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20> <20><><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> 0");
|
|
|
|
|
}
|
2024-05-29 23:03:32 +04:00
|
|
|
|
|
2024-05-29 18:32:24 +04:00
|
|
|
|
Response.Redirect("CreateOrder");
|
|
|
|
|
}
|
|
|
|
|
}
|
2024-05-25 17:47:14 +04:00
|
|
|
|
}
|