This commit is contained in:
Игорь Гордеев 2024-05-29 21:23:34 +04:00
parent 06baeba759
commit d196786cde
5 changed files with 22 additions and 12 deletions

View File

@ -46,7 +46,7 @@ namespace ElectronicsShopBusinessLogic.BusinessLogic
if (string.IsNullOrEmpty((model.ID).ToString())) {
throw new ArgumentNullException("Нет ID заказа", nameof(model.ID));
}
if (model.Sum <= 0) {
if (model.Sum <= 0) {////byda
throw new ArgumentNullException("Цена зака должна быть больше 0", nameof(model.Sum));
}
if (model.ClientID < 0) {
@ -59,7 +59,7 @@ namespace ElectronicsShopBusinessLogic.BusinessLogic
{
if (model == null) throw new ArgumentNullException(nameof(model));
_logger.LogInformation($"ReadElement. ID:{model.ID}");
var element = _storage.GetElement(model);//Не находит в бд
var element = _storage.GetElement(model);
if (element == null)
{
_logger.LogWarning("ReadElement. elementn not found");

View File

@ -103,10 +103,20 @@ namespace ElectronicsShopRestAPI.Controllers {
{
try
{
if (_order.ReadElement(new OrderSearchModel { ID = model.ID })==null)
{
CreateOrder( new OrderBindingModel
{
ClientID = model.ClientID,
ProductList = model.ProductList,//Суда поступает пустой список
Sum = model.Sum
});
}
var order=_order.ReadElement(new OrderSearchModel { ID = model.ID });//возвращает null
if (model != null&& order!=null)
{
order.ProductList = model.ProductList;
order.Sum = model.Sum;
}
}
catch (Exception ex)

View File

@ -94,7 +94,6 @@ namespace ElectronicsShopUserApp.Controllers {
[HttpGet]
public IActionResult CreateOrder() {
ViewBag.Products = APIClient.GetRequset<List<ProductViewModel>>("api/main/getproducts");
return View();
}
[HttpPost]
@ -107,8 +106,7 @@ namespace ElectronicsShopUserApp.Controllers {
{
throw new Exception("Êîëè÷åñòâî è ñóììà äîëæíû áûòü áîëüøå 0");
}
Response.Redirect("Index");
Response.Redirect("Index");
}
[HttpPost]
private double CalcAll(Dictionary<int, (IProductModel, int)> ProductList)
@ -121,7 +119,7 @@ namespace ElectronicsShopUserApp.Controllers {
return Sum;
}
[HttpPost]
public double CalcProduct(int count, int product)
public double Calc(int count, int product)
{
var prod =
APIClient.GetRequset<ProductViewModel>($"api/main/getproduct?productID={product}"

View File

@ -1,5 +1,5 @@
@{
ViewData["Title"] = "Add Product";
ViewData["Title"] = "AddProduct";
}
<div class="text-center">
<h2 class="display-4">Создание заказа</h2>
@ -34,7 +34,9 @@
<input type="submit" value="Добавить" class="btn btn-primary" />
</div>
</div>
<script src="~/lib/jquery/dist/jquery.min.js"></script>
</form>
<script>
$('#product').on('change', function () {
check();
@ -48,8 +50,8 @@
if (count && product) {
$.ajax({
method: "POST",
url: "/Home/CalcProduct",
data: { count: count, product: product.price },
url: "/Home/Calc",
data: { count: count, product: product },
success: function (result) {
var roundedResult = parseFloat(result).toFixed(2);
$("#sum").val(roundedResult);

View File

@ -38,13 +38,13 @@
{
<th>
<th>
@Html.DisplayFor(modelItem => item.Value.Item1.ProductName)
@Html.DisplayFor(modelItem => item.Value.Item1.ProductName)
</th>
<th>
@Html.DisplayFor(modelItem => item.Value.Item2)
@Html.DisplayFor(modelItem => item.Value.Item2)
</th>
<th>
@Html.DisplayFor(modelItem => item.Value.Item1.Price*item.Value.Item2)
@Html.DisplayFor(modelItem => item.Value.Item1.Price*item.Value.Item2)
</th>
</th>
}