diff --git a/Areas/Inventory/Views/InventoryMaster/ManifacturerRegistration.cshtml b/Areas/Inventory/Views/InventoryMaster/ManifacturerRegistration.cshtml index 6a7f51a..5c826c4 100644 --- a/Areas/Inventory/Views/InventoryMaster/ManifacturerRegistration.cshtml +++ b/Areas/Inventory/Views/InventoryMaster/ManifacturerRegistration.cshtml @@ -247,38 +247,58 @@ } }, - async deleteManufacturer(manufacturerId) { - if (!confirm("Are you sure you want to delete this manufacturer?")) { - return; - } - try { - const response = await fetch(`/InvMainAPI/DeleteManufacturer/${manufacturerId}`, { - method: 'DELETE', - headers: { - 'Content-Type': 'application/json', - }, - }); - const result = await response.json(); + async deleteManufacturer(manufacturerId) { + if (!confirm("Are you sure you want to delete this manufacturer?")) { + return; + } + try { + const response = await fetch(`/InvMainAPI/DeleteManufacturer/${manufacturerId}`, { + method: 'DELETE', + headers: { + 'Content-Type': 'application/json', + }, + }); - if (result.success) { - alert(result.message); - // Remove the row from DataTables - this.manufacturerDatatable - .row($(`.delete-btn[data-id="${manufacturerId}"]`).closest('tr')) - .remove() - .draw(); - } else { - alert(result.message); + // Check if the response was successful (status 2xx) + if (response.ok) { + const result = await response.json(); // Expect a success JSON object + alert(result.message); + // Remove the row from DataTables + this.manufacturerDatatable + .row($(`.delete-btn[data-id="${manufacturerId}"]`).closest('tr')) + .remove() + .draw(); + } else { + // If response is not OK, try to parse JSON error message + let errorMessage = "An unknown error occurred."; + try { + const errorData = await response.json(); + errorMessage = errorData.message || errorMessage; + } catch (jsonError) { + // If parsing JSON fails, it might be a raw error message + errorMessage = await response.text(); // Get the raw text + console.error("Failed to parse error response as JSON:", jsonError, "Raw response:", errorMessage); + // A more user-friendly message for generic errors: + if (response.status === 404) { + errorMessage = "Manufacturer not found."; + } else if (response.status === 400) { + // This will catch the "This manufacturer cannot be deleted..." message from your API + errorMessage = errorMessage; // Use the message directly if it's already friendly + } else { + errorMessage = "An unexpected error occurred on the server."; + } } - } - catch (error) { - console.error("Error deleting manufacturer:", error); - alert("An error occurred while deleting the manufacturer."); + alert(errorMessage); } - finally { - this.loading = false; - } - }, + } + catch (error) { + console.error("Error deleting manufacturer:", error); + alert("An error occurred while trying to delete the manufacturer. Please check your network connection or try again."); + } + finally { + this.loading = false; + } + }, } }); diff --git a/Areas/Inventory/Views/InventoryMaster/SupplierRegistration.cshtml b/Areas/Inventory/Views/InventoryMaster/SupplierRegistration.cshtml index de8c89a..0434e0e 100644 --- a/Areas/Inventory/Views/InventoryMaster/SupplierRegistration.cshtml +++ b/Areas/Inventory/Views/InventoryMaster/SupplierRegistration.cshtml @@ -25,7 +25,7 @@ - @* Supplier Gender *@ + @* Supplier Address *@