Работает

This commit is contained in:
Андрей Байгулов 2024-05-03 20:58:25 +04:00
parent dd5b7df500
commit c920c54e17
2 changed files with 13 additions and 14 deletions

View File

@ -112,12 +112,12 @@ namespace SushiBarClientApp.Controllers
[HttpGet]
public IActionResult Create()
{
ViewBag.Products =
APIClient.GetRequest<List<SushiViewModel>>("api/main/getproductlist");
ViewBag.Sushis =
APIClient.GetRequest<List<SushiViewModel>>("api/main/getsushilist");
return View();
}
[HttpPost]
public void Create(int product, int count)
public void Create(int sushi, int count)
{
if (APIClient.Client == null)
{
@ -131,17 +131,17 @@ namespace SushiBarClientApp.Controllers
OrderBindingModel
{
ClientId = APIClient.Client.Id,
SushiId = product,
SushiId = sushi,
Count = count,
Sum = Calc(count, product)
Sum = Calc(count, sushi)
});
Response.Redirect("Index");
}
[HttpPost]
public double Calc(int count, int product)
public double Calc(int count, int sushi)
{
var prod =
APIClient.GetRequest<SushiViewModel>($"api/main/getproduct?productId={product}"
APIClient.GetRequest<SushiViewModel>($"api/main/getsushi?sushiId={sushi}"
);
return count * (prod?.Price ?? 1);
}

View File

@ -8,7 +8,7 @@
<div class="row">
<div class="col-4">Изделие:</div>
<div class="col-8">
<select id="product" name="product" class="form-control" aspitems="@(new SelectList(@ViewBag.Products,"Id", "ProductName"))"></select>
<select id="sushi" name="sushi" class="form-control" aspitems="@(new SelectList(@ViewBag.sushis,"Id", "SushiName"))"></select>
</div>
</div>
<div class="row">
@ -26,13 +26,12 @@
<div class="row">
<div class="col-8"></div>
<div class="col-4">
<input type="submit" value="Создать" class="btn
btn-primary" />
<input type="submit" value="Создать" class="btnbtn-primary" />
</div>
</div>
</form>
<script>
$('#product').on('change', function () {
$('#sushi').on('change', function () {
check();
});
$('#count').on('change', function () {
@ -40,11 +39,11 @@ btn-primary" />
});
function check() {
var count = $('#count').val();
var product = $('#product').val();
if (count && product) {
var sushi = $('#sushi').val();
if (count && sushi) {
$.ajax({
method: "POST",
url: "/Home/Calc", data: { count: count, product: product },
url: "/Home/Calc", data: { count: count, sushi: sushi },
success: function (result) {
$("#sum").val(result);
}