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

View File

@ -103,10 +103,20 @@ namespace ElectronicsShopRestAPI.Controllers {
{ {
try 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 var order=_order.ReadElement(new OrderSearchModel { ID = model.ID });//возвращает null
if (model != null&& order!=null) if (model != null&& order!=null)
{ {
order.ProductList = model.ProductList; order.ProductList = model.ProductList;
order.Sum = model.Sum;
} }
} }
catch (Exception ex) catch (Exception ex)

View File

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

View File

@ -34,7 +34,9 @@
<input type="submit" value="Добавить" class="btn btn-primary" /> <input type="submit" value="Добавить" class="btn btn-primary" />
</div> </div>
</div> </div>
<script src="~/lib/jquery/dist/jquery.min.js"></script>
</form> </form>
<script> <script>
$('#product').on('change', function () { $('#product').on('change', function () {
check(); check();
@ -48,8 +50,8 @@
if (count && product) { if (count && product) {
$.ajax({ $.ajax({
method: "POST", method: "POST",
url: "/Home/CalcProduct", url: "/Home/Calc",
data: { count: count, product: product.price }, data: { count: count, product: product },
success: function (result) { success: function (result) {
var roundedResult = parseFloat(result).toFixed(2); var roundedResult = parseFloat(result).toFixed(2);
$("#sum").val(roundedResult); $("#sum").val(roundedResult);