diff --git a/Nop.Plugin.Misc.AIPlugin/Areas/Admin/Controllers/CustomOrderController.cs b/Nop.Plugin.Misc.AIPlugin/Areas/Admin/Controllers/CustomOrderController.cs index aa29b8a..e29eb06 100644 --- a/Nop.Plugin.Misc.AIPlugin/Areas/Admin/Controllers/CustomOrderController.cs +++ b/Nop.Plugin.Misc.AIPlugin/Areas/Admin/Controllers/CustomOrderController.cs @@ -1056,7 +1056,33 @@ namespace Nop.Plugin.Misc.FruitBankPlugin.Areas.Admin.Controllers return RedirectToAction("List"); } } - #endregion + #endregion + + [HttpPost] + [ValidateAntiForgeryToken] + public async Task SendOrderNotification(int orderId, string message) + { + try + { + + if (string.IsNullOrWhiteSpace(message)) + { + return Json(new { success = false, message = "Az üzenet nem lehet üres" }); + } + + var orderDto = await _dbContext.OrderDtos.GetByIdAsync(orderId, true); + await _sendToClient.SendMeasuringNotification("Módosult a rendelés, mérjétek újra!", orderDto); + return Json(new { success = true, message = "Üzenet sikeresen elküldve" }); + } + catch (Exception ex) + { + + _logger.Error($"Error sending notification for order {orderId}", ex); + + return Json(new { success = false, message = $"Hiba történt: {ex.Message}" }); + } + } + } } diff --git a/Nop.Plugin.Misc.AIPlugin/Views/OrderAttributes.cshtml b/Nop.Plugin.Misc.AIPlugin/Views/OrderAttributes.cshtml index 97ec4f0..35080be 100644 --- a/Nop.Plugin.Misc.AIPlugin/Views/OrderAttributes.cshtml +++ b/Nop.Plugin.Misc.AIPlugin/Views/OrderAttributes.cshtml @@ -1,12 +1,44 @@ @using Nop.Plugin.Misc.FruitBankPlugin.Models.Orders @model OrderAttributesModel - - + + +
+
+
+
+

Üzenet küldése

+
+
+
+
+ + +
+
+
+
+ +
+
+
+
+ +
+
+
+
+
+
+
-
+
Megrendelés beállítások @@ -415,5 +447,76 @@ updateInvoiceButtons(); } }); + + + var sendNotificationUrl = '/Admin/CustomOrder/SendOrderNotification'; + + // Send Notification + $("#sendNotificationBtn").click(function (e) { + e.preventDefault(); + e.stopPropagation(); + + var message = $("#notificationMessage").val().trim(); + + if (!message) { + showNotificationStatus("Kérjük, adjon meg egy üzenetet!", "warning"); + return false; + } + + var btn = $(this); + btn.prop("disabled", true).html(' Küldés...'); + + showNotificationStatus("Üzenet küldése folyamatban...", "info"); + + $.ajax({ + type: "POST", + url: sendNotificationUrl, + data: { + orderId: @Model.OrderId, + message: message, + __RequestVerificationToken: $('input[name="__RequestVerificationToken"]').val() + }, + dataType: 'json', + success: function (response) { + console.log("Notification Response:", response); + btn.prop("disabled", false).html(' Üzenet küldése'); + + if (response.success) { + showNotificationStatus("Üzenet sikeresen elküldve!", "success"); + $("#notificationMessage").val(""); // Clear the textbox + } else { + showNotificationStatus("Hiba: " + (response.message || "Ismeretlen hiba"), "danger"); + } + }, + error: function (xhr, status, error) { + console.error("Notification AJAX Error:", xhr, status, error); + btn.prop("disabled", false).html(' Üzenet küldése'); + + var errorMessage = "Hiba az üzenet küldése közben"; + if (xhr.responseJSON && xhr.responseJSON.message) { + errorMessage = xhr.responseJSON.message; + } else if (xhr.responseText) { + try { + var errorObj = JSON.parse(xhr.responseText); + errorMessage = errorObj.message || errorMessage; + } catch (e) { + errorMessage = "Hiba: " + xhr.status + " - " + xhr.statusText; + } + } + showNotificationStatus(errorMessage, "danger"); + } + }); + + return false; + }); + + function showNotificationStatus(message, type) { + var statusDiv = $("#notificationStatus"); + statusDiv.removeClass("alert-info alert-success alert-warning alert-danger") + .addClass("alert-" + type); + $("#notificationStatusMessage").text(message); + statusDiv.show(); + } + }); \ No newline at end of file