Order sum fix
This commit is contained in:
parent
216356dd73
commit
623a3dde7e
@ -87,11 +87,12 @@ namespace ElectronicsShopDataBaseImplement.Models
|
||||
context.SaveChanges();
|
||||
}
|
||||
var order = context.Orders.First(x => x.ID == model.ID);
|
||||
order.Sum = model.Sum;
|
||||
foreach (var op in model.ProductList) {
|
||||
context.OrderProducts.Add(new OrderProduct {
|
||||
_order = order,
|
||||
_product = context.Products.First(x => x.ID == op.Key),
|
||||
Count = op.Value.Item2
|
||||
Count = op.Value.Item2,
|
||||
});
|
||||
context.SaveChanges();
|
||||
}
|
||||
|
@ -161,7 +161,7 @@ namespace ElectronicsShopRestAPI.Controllers {
|
||||
ClientID = view.ClientID,
|
||||
DateCreate = view.DateCreate,
|
||||
ProductList = _productlist,
|
||||
//sum
|
||||
Sum = Calc(_productlist)
|
||||
};
|
||||
var operationResult = _order.Update(model);
|
||||
if (!operationResult) {
|
||||
@ -198,8 +198,8 @@ namespace ElectronicsShopRestAPI.Controllers {
|
||||
ID = _orderId,
|
||||
ClientID = view.ClientID,
|
||||
DateCreate = view.DateCreate,
|
||||
ProductList = _productlist
|
||||
//sum
|
||||
ProductList = _productlist,
|
||||
Sum = Calc(_productlist)
|
||||
};
|
||||
var operationResult = _order.DeleteProduct(model);
|
||||
if (!operationResult) {
|
||||
@ -211,5 +211,14 @@ namespace ElectronicsShopRestAPI.Controllers {
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
[HttpPost]
|
||||
public double Calc(Dictionary<int, (IProductModel, int)> _productlist) {
|
||||
double ans = 0;
|
||||
foreach (var item in _productlist) {
|
||||
ans += item.Value.Item1.Price * item.Value.Item2;
|
||||
}
|
||||
return ans;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -75,7 +75,7 @@
|
||||
<div class="row">
|
||||
<div class="col-4"></div>
|
||||
<div class="col-8">
|
||||
<input type="submit" value="Заказ готова, вернуться!" class="btn btn-primary" />
|
||||
<input type="submit" value="Заказ готов, вернуться!" class="btn btn-primary" />
|
||||
<a class="btn btn-primary btn-sm" asp-action="DeleteOrder" asp-route-ID="@Model.Item1">Удалить</a>
|
||||
</div>
|
||||
</div>
|
||||
|
@ -76,7 +76,7 @@
|
||||
<div class="row">
|
||||
<div class="col-4"></div>
|
||||
<div class="col-8">
|
||||
<input type="submit" value="Заказ готова, вернуться!" class="btn btn-primary" />
|
||||
<input type="submit" value="Заказ готов, вернуться!" class="btn btn-primary" />
|
||||
<a class="btn btn-primary btn-sm" asp-action="DeleteOrder" asp-route-ID="@Model.Item1">Отменить создание корзины</a>
|
||||
</div>
|
||||
</div>
|
||||
|
@ -12,7 +12,7 @@
|
||||
<header>
|
||||
<nav class="navbar navbar-expand-sm navbar-toggleable-sm navbar-light bg-white border-bottom box-shadow mb-3">
|
||||
<div class="container-fluid">
|
||||
<a class="navbar-brand" asp-area="" asp-controller="Home" asp-action="Index">ElectronicsShopClientApp</a>
|
||||
<a class="navbar-brand" asp-area="" asp-controller="Home" asp-action="Index">Магазин электроники (Клиент)</a>
|
||||
<button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target=".navbar-collapse" aria-controls="navbarSupportedContent"
|
||||
aria-expanded="false" aria-label="Toggle navigation">
|
||||
<span class="navbar-toggler-icon"></span>
|
||||
|
Loading…
Reference in New Issue
Block a user