This commit is contained in:
Илья Федотов 2024-05-29 21:45:45 +04:00
commit 2bba322faa
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,7 +106,6 @@ namespace ElectronicsShopUserApp.Controllers {
{
throw new Exception("Êîëè÷åñòâî è ñóììà äîëæíû áûòü áîëüøå 0");
}
Response.Redirect("Index");
}
[HttpPost]
@ -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

@ -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);