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-06-01 05:00:05 +04:00
|
|
|
|
using ElectronicsShopDataModels.Enums;
|
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;
|
2024-05-31 16:05:43 +04:00
|
|
|
|
using Newtonsoft.Json;
|
2024-05-25 17:47:14 +04:00
|
|
|
|
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;
|
2024-05-31 16:05:43 +04:00
|
|
|
|
using System.Xml.Serialization;
|
2024-05-25 17:47:14 +04:00
|
|
|
|
|
|
|
|
|
namespace ElectronicsShopUserApp.Controllers {
|
|
|
|
|
public class HomeController : Controller {
|
|
|
|
|
private readonly ILogger<HomeController> _logger;
|
2024-05-30 20:32:16 +04:00
|
|
|
|
private Dictionary<int, (IProductModel, int)> _productList;
|
2024-06-01 00:42:46 +04:00
|
|
|
|
public int Id;
|
2024-05-30 20:32:16 +04:00
|
|
|
|
//private readonly IOrderLogic _order;
|
2024-05-25 17:47:14 +04:00
|
|
|
|
|
2024-05-30 20:33:25 +04:00
|
|
|
|
public HomeController(ILogger<HomeController> logger/*, IOrderLogic orderLogic*/) {
|
2024-05-25 17:47:14 +04:00
|
|
|
|
_logger = logger;
|
2024-05-30 20:33:25 +04:00
|
|
|
|
//_order = orderLogic;
|
2024-05-31 16:05:43 +04:00
|
|
|
|
_productList = new Dictionary<int, (IProductModel, int)>();
|
2024-05-25 17:47:14 +04:00
|
|
|
|
}
|
|
|
|
|
|
2024-06-01 06:31:02 +04:00
|
|
|
|
[HttpGet]
|
2024-05-25 17:47:14 +04:00
|
|
|
|
public IActionResult Index() {
|
|
|
|
|
if (APIClient.Client == null) {
|
|
|
|
|
return Redirect("~/Home/Enter");
|
|
|
|
|
}
|
2024-06-01 06:31:02 +04:00
|
|
|
|
|
|
|
|
|
var view = APIClient.GetRequset<List<PaymeantViewModel>>($"api/main/getpaymeants?_clientid={APIClient.Client.ID}");
|
|
|
|
|
return View(view);
|
2024-05-25 17:47:14 +04:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[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;
|
|
|
|
|
}
|
|
|
|
|
|
2024-05-30 20:32:16 +04:00
|
|
|
|
public IActionResult Orders() {
|
|
|
|
|
if (APIClient.Client == null) {
|
|
|
|
|
return Redirect("~/Home/Enter");
|
|
|
|
|
}
|
2024-05-30 23:49:53 +04:00
|
|
|
|
|
2024-05-31 16:05:43 +04:00
|
|
|
|
var view = APIClient.GetRequset<List<OrderViewModel>>($"api/main/getorders?_clientid={APIClient.Client.ID}");
|
2024-05-30 23:49:53 +04:00
|
|
|
|
|
2024-05-31 16:05:43 +04:00
|
|
|
|
return View(view);
|
2024-05-30 20:32:16 +04:00
|
|
|
|
}
|
|
|
|
|
|
2024-05-25 17:47:14 +04:00
|
|
|
|
[HttpGet]
|
2024-05-30 20:32:16 +04:00
|
|
|
|
public IActionResult CreateOrder() {
|
2024-05-30 23:49:53 +04:00
|
|
|
|
if (APIClient.Client == null) {
|
|
|
|
|
return Redirect("~/Home/Enter");
|
|
|
|
|
}
|
|
|
|
|
APIClient.PostRequest("api/main/createorder", new OrderBindingModel {
|
|
|
|
|
ClientID = APIClient.Client.ID,
|
|
|
|
|
DateCreate = DateTime.Now,
|
|
|
|
|
});
|
|
|
|
|
return RedirectToAction("OrderView");
|
2024-05-30 20:32:16 +04:00
|
|
|
|
}
|
2024-05-29 23:03:32 +04:00
|
|
|
|
|
2024-05-30 23:49:53 +04:00
|
|
|
|
[HttpGet]
|
2024-06-01 00:42:46 +04:00
|
|
|
|
public IActionResult DeleteOrder(int id) {
|
|
|
|
|
APIClient.PostRequest($"api/main/deleteorders", new OrderBindingModel { ID = id });
|
|
|
|
|
return RedirectToAction("Orders");
|
|
|
|
|
}
|
|
|
|
|
|
2024-06-01 02:22:06 +04:00
|
|
|
|
[HttpGet]
|
|
|
|
|
public IActionResult EditOrder(int id) {
|
|
|
|
|
if (APIClient.Client == null) {
|
|
|
|
|
return Redirect("~/Home/Enter");
|
|
|
|
|
}
|
|
|
|
|
|
2024-06-01 02:45:59 +04:00
|
|
|
|
if (id == 0) {
|
2024-06-01 03:37:37 +04:00
|
|
|
|
return RedirectToAction("Orders");
|
2024-06-01 02:45:59 +04:00
|
|
|
|
}
|
2024-06-01 02:22:06 +04:00
|
|
|
|
var products = APIClient.GetRequset<List<List<string>>>($"api/main/getorderproducts?_orderid={id}");
|
|
|
|
|
|
|
|
|
|
foreach (var pr in products) {
|
|
|
|
|
var product = JsonConvert.DeserializeObject<ProductViewModel>(pr[0]);
|
|
|
|
|
int count = JsonConvert.DeserializeObject<int>(pr[1]);
|
|
|
|
|
_productList.Add(product.ID, (product, count));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
(int, Dictionary<int, (IProductModel, int)>) tuple = (id, _productList);
|
|
|
|
|
return View(tuple);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[HttpPost]
|
2024-06-01 05:00:05 +04:00
|
|
|
|
public void EditOrder(double sum, int id) {
|
2024-06-01 02:22:06 +04:00
|
|
|
|
if (sum <= 0) {
|
|
|
|
|
APIClient.PostRequest($"api/main/deleteorders", new OrderBindingModel { ID = id });
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Response.Redirect("Orders");
|
|
|
|
|
}
|
|
|
|
|
|
2024-06-01 00:42:46 +04:00
|
|
|
|
[HttpGet]
|
2024-05-30 23:49:53 +04:00
|
|
|
|
public IActionResult OrderView() {
|
|
|
|
|
if (APIClient.Client == null) {
|
|
|
|
|
return Redirect("~/Home/Enter");
|
|
|
|
|
}
|
|
|
|
|
var view = APIClient.GetRequset<OrderViewModel>($"api/main/getorder?_clientid={APIClient.Client?.ID}");
|
2024-06-01 00:42:46 +04:00
|
|
|
|
if (view != null) {
|
|
|
|
|
Id = view.ID;
|
|
|
|
|
}
|
|
|
|
|
|
2024-05-31 16:05:43 +04:00
|
|
|
|
var products = APIClient.GetRequset<List<List<string>>>($"api/main/getorderproducts?_orderid={view?.ID}");
|
2024-05-30 23:49:53 +04:00
|
|
|
|
|
2024-05-31 16:05:43 +04:00
|
|
|
|
foreach (var pr in products) {
|
|
|
|
|
var product = JsonConvert.DeserializeObject<ProductViewModel>(pr[0]);
|
|
|
|
|
int count = JsonConvert.DeserializeObject<int>(pr[1]);
|
|
|
|
|
_productList.Add(product.ID, (product, count));
|
|
|
|
|
}
|
|
|
|
|
|
2024-06-01 00:42:46 +04:00
|
|
|
|
(int, Dictionary<int, (IProductModel, int)>) tuple = (Id, _productList);
|
|
|
|
|
return View(tuple);
|
2024-05-31 16:05:43 +04:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[HttpPost]
|
2024-06-01 05:00:05 +04:00
|
|
|
|
public void OrderView(double sum, int id) {
|
2024-06-01 00:42:46 +04:00
|
|
|
|
if (sum <= 0) {
|
|
|
|
|
APIClient.PostRequest($"api/main/deleteorders", new OrderBindingModel { ID = id});
|
|
|
|
|
}
|
2024-05-31 16:05:43 +04:00
|
|
|
|
Response.Redirect("Orders");
|
2024-05-30 23:49:53 +04:00
|
|
|
|
}
|
|
|
|
|
|
2024-06-01 00:42:46 +04:00
|
|
|
|
[HttpGet]
|
|
|
|
|
public IActionResult DeleteProductOrder(int id) {
|
|
|
|
|
var view = APIClient.GetRequset<OrderViewModel>($"api/main/getorder?_clientid={APIClient.Client?.ID}");
|
|
|
|
|
APIClient.PostRequestStr($"api/main/deleteproductorder", view.ID, id);
|
|
|
|
|
|
|
|
|
|
return RedirectToAction("OrderView");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[HttpGet]
|
2024-05-30 20:32:16 +04:00
|
|
|
|
public IActionResult AddProduct() {
|
|
|
|
|
ViewBag.Products = APIClient.GetRequset<List<ProductViewModel>>($"api/main/getproducts");
|
|
|
|
|
return View();
|
2024-05-25 17:47:14 +04:00
|
|
|
|
}
|
2024-05-30 20:32:16 +04:00
|
|
|
|
|
|
|
|
|
[HttpPost]
|
2024-05-30 23:49:53 +04:00
|
|
|
|
public void AddProduct(int product, int count) {
|
|
|
|
|
var _product = APIClient.GetRequset<ProductViewModel>($"api/main/getproduct?_productid={product}");
|
|
|
|
|
var _order = APIClient.GetRequset<OrderViewModel>($"api/main/getorder?_clientid={APIClient.Client?.ID}");
|
2024-05-30 20:32:16 +04:00
|
|
|
|
|
2024-05-30 23:49:53 +04:00
|
|
|
|
APIClient.ListPostRequest($"api/main/addproduct", _product, count, _order.ID);
|
|
|
|
|
Response.Redirect("OrderView");
|
2024-05-30 20:32:16 +04:00
|
|
|
|
}
|
|
|
|
|
|
2024-06-01 02:22:36 +04:00
|
|
|
|
[HttpGet]
|
|
|
|
|
public IActionResult Report()
|
|
|
|
|
{
|
|
|
|
|
return View();
|
2024-06-01 02:50:15 +04:00
|
|
|
|
}
|
|
|
|
|
[HttpPost]
|
|
|
|
|
public void Report(int count)
|
|
|
|
|
{
|
|
|
|
|
|
2024-06-01 02:22:36 +04:00
|
|
|
|
}
|
|
|
|
|
[HttpGet]
|
|
|
|
|
public IActionResult Message()
|
|
|
|
|
{
|
|
|
|
|
//ViewBag.Reports = APIClient.GetRequset<List<ProductViewModel>>($"api/main/getproducts"); <20><><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD> <20><> <20><><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD>
|
|
|
|
|
return View();
|
2024-06-01 03:18:46 +04:00
|
|
|
|
}
|
2024-06-01 05:00:05 +04:00
|
|
|
|
|
|
|
|
|
[HttpGet]
|
2024-06-01 03:18:46 +04:00
|
|
|
|
public IActionResult Payment(int id)
|
|
|
|
|
{
|
|
|
|
|
if (APIClient.Client == null)
|
|
|
|
|
{
|
|
|
|
|
return Redirect("~/Home/Enter");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (id == 0)
|
|
|
|
|
{
|
2024-06-01 05:00:05 +04:00
|
|
|
|
return Redirect("~/Home/Index");
|
2024-06-01 03:18:46 +04:00
|
|
|
|
}
|
|
|
|
|
var products = APIClient.GetRequset<List<List<string>>>($"api/main/getorderproducts?_orderid={id}");
|
|
|
|
|
|
|
|
|
|
foreach (var pr in products)
|
|
|
|
|
{
|
|
|
|
|
var product = JsonConvert.DeserializeObject<ProductViewModel>(pr[0]);
|
|
|
|
|
int count = JsonConvert.DeserializeObject<int>(pr[1]);
|
|
|
|
|
_productList.Add(product.ID, (product, count));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
(int, Dictionary<int, (IProductModel, int)>) tuple = (id, _productList);
|
|
|
|
|
return View(tuple);
|
|
|
|
|
}
|
2024-06-01 05:00:05 +04:00
|
|
|
|
|
|
|
|
|
[HttpPost]
|
|
|
|
|
public void Payment(double sum, double paysum, int id) {
|
|
|
|
|
if (APIClient.Client == null) {
|
|
|
|
|
throw new Exception("<22><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>");
|
|
|
|
|
}
|
|
|
|
|
if (paysum <= 0) {
|
|
|
|
|
throw new Exception("<22><><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> 0");
|
|
|
|
|
}
|
|
|
|
|
if (paysum > sum) {
|
|
|
|
|
throw new Exception("<22><><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD> <20> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>");
|
|
|
|
|
}
|
|
|
|
|
APIClient.PostRequest("api/client/createpaymeant", new PaymeantBindingModel {
|
|
|
|
|
OrderID = id,
|
2024-06-01 05:23:37 +04:00
|
|
|
|
SumPayment = paysum,
|
|
|
|
|
PayOption = PayOptionCalc(sum, paysum),
|
|
|
|
|
ClientID = APIClient.Client.ID
|
2024-06-01 05:00:05 +04:00
|
|
|
|
});
|
|
|
|
|
Response.Redirect("Index");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[HttpPost]
|
|
|
|
|
public PaymeantOption PayOptionCalc(double sum, double paysum) {
|
|
|
|
|
if (paysum < sum) {
|
|
|
|
|
return PaymeantOption.<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>_<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>;
|
|
|
|
|
}
|
|
|
|
|
else if (paysum == sum) {
|
|
|
|
|
return PaymeantOption.<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>_<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>;
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
return PaymeantOption.<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>;
|
|
|
|
|
}
|
|
|
|
|
}
|
2024-06-01 03:39:57 +04:00
|
|
|
|
|
2024-06-01 02:22:36 +04:00
|
|
|
|
}
|
2024-05-25 17:47:14 +04:00
|
|
|
|
}
|