This commit is contained in:
Илья Федотов 2024-06-01 02:22:06 +04:00
parent d45167de0d
commit 79d137fdc9
3 changed files with 132 additions and 0 deletions

View File

@ -127,6 +127,8 @@ namespace ElectronicsShopRestAPI.Controllers {
}
}
[HttpPost]
public void AddProduct(List<string> jslist)
{

View File

@ -128,6 +128,33 @@ namespace ElectronicsShopUserApp.Controllers {
return RedirectToAction("Orders");
}
[HttpGet]
public IActionResult EditOrder(int id) {
if (APIClient.Client == null) {
return Redirect("~/Home/Enter");
}
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]
public void EditOrder(int sum, int id) {
if (sum <= 0) {
APIClient.PostRequest($"api/main/deleteorders", new OrderBindingModel { ID = id });
}
Response.Redirect("Orders");
}
[HttpGet]
public IActionResult OrderView() {
if (APIClient.Client == null) {

View File

@ -0,0 +1,103 @@
@using ElectronicsShopContracts.ViewModels
@using ElectronicsShopDataModels.Models
@model (int, Dictionary<int, (IProductModel, int)>)
@{
ViewData["Title"] = "EditOrder";
}
<div class="text-center">
<h1 class="display-4">Создание корзины</h1>
</div>
<form method="post">
<div class="row">
<div class="col-4"></div>
<div class="col-8">
<input id="id" type="hidden" name="id" readonly value="@Model.Item1" />
</div>
</div>
<div class=" text-center">
<div class="row">
<div class="col-4">Сумма:</div>
<div class="col-8">
<input id="sum" type="text" name="sum" readonly />
</div>
</div>
<p>
<a asp-action="AddProduct">Добавить товар</a>
</p>
<table class="table">
<thead>
<tr>
<th>
Номер
</th>
<th>
Продукт
</th>
<th>
Количество
</th>
<th>
Сумма
</th>
</tr>
</thead>
<tbody>
@foreach (var item in Model.Item2) {
<tr class="element">
<th>
@Html.DisplayFor(modelItem => item.Key)
</th>
<th>
@Html.DisplayFor(modelItem => item.Value.Item1.ProductName)
</th>
<th class="count">
@Html.DisplayFor(modelItem => item.Value.Item2)
</th>
<th class="countsum">
@Html.DisplayFor(modelItem => item.Value.Item1.Price)
</th>
<td>
<a class="btn btn-primary btn-sm" asp-action="DeleteProductOrder" asp-route-ID="@item.Key">Удалить</a>
</td>
</tr>
}
</tbody>
</table>
<div class="row">
<div class="col-4"></div>
<div class="col-8">
<input type="submit" value="Заказ готова, вернуться!" class="btn btn-primary" />
</div>
</div>
</div>
<script src="~/lib/jquery/dist/jquery.min.js"></script>
</form>
<script>
$('btn').on('click', function () {
calc();
});
let sum = 0;
const elementRows = document.querySelectorAll('.element');
calc();
function calc() {
elementRows.forEach(row => {
const count = parseInt(row.querySelector('.count').innerHTML, 10);
const countsum = parseInt(row.querySelector('.countsum').innerHTML, 10);
const rowTotal = count * countsum;
sum += rowTotal;
});
$('#sum').val(sum);
}
</script>