REGISTRATION PRODUCT
@@ -137,7 +126,7 @@
el: '#registerProduct',
data: {
productName: null,
- manufacturer: '',
+ manufacturer: null,
category: null,
modelNo: null,
quantityProduct: null,
@@ -274,7 +263,29 @@
this.imageSrc = '';
this.imageProduct = null;
}
- }
+ },
+ async fetchManufactures() {
+ fetch('/InvMainAPI/ManufacturerList', {
+ method: 'POST'
+ })
+ .then(response => response.json())
+ .then(data => {
+ console.log(data);
+ if (data != null && data.length > 0)
+ {
+ this.manufacturer = data;
+ }
+ if (!this.manufacturerDatatable) {
+ this.initiateTable();
+ } else {
+ this.fillTable(data);
+ }
+ })
+ .catch(error => {
+ console.error('There was a problem with the fetch operation:', error);
+ });
+
+ },
}
});
diff --git a/Areas/Inventory/Views/Main/ManifacturerRegistration.cshtml b/Areas/Inventory/Views/Main/ManifacturerRegistration.cshtml
index 09a02a5..a8bbb7f 100644
--- a/Areas/Inventory/Views/Main/ManifacturerRegistration.cshtml
+++ b/Areas/Inventory/Views/Main/ManifacturerRegistration.cshtml
@@ -3,10 +3,11 @@
Layout = "~/Views/Shared/_Layout.cshtml";
}
+@await Html.PartialAsync("~/Areas/Inventory/Views/_InventoryPartial.cshtml");
-
@@ -14,7 +15,7 @@
Loading...
-
+
@@ -96,13 +97,21 @@
},
{ "title": "Delete",
"data": "manufacturerName",
- "render": function (data, type, full, meta) {
- var deleteButton = `
`;
- return deleteButton;
- }
+ "render": function (data, type, full, meta) {
+ var deleteButton = `
`;
+ return deleteButton;
+ },
+ "width": '10%',
},
],
})
+ self = this;
+ // Attach click event listener to the delete buttons
+ $('#manufacturerTable tbody').on('click', '.delete-btn', function () {
+ const manufacturerId = $(this).data('id'); // Get the manufacturer ID from the button
+ self.deleteManufacturer(manufacturerId); // Call the Vue method
+ });
+
this.loading = false;
},
fillTable(data){
@@ -145,10 +154,40 @@
this.newManufacturer.manufacturerName = null;
});
},
- deleteManufacturer(Id){
- console.log(Id)
- }
+ 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();
+
+ 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);
+ }
+ }
+ catch (error) {
+ console.error("Error deleting manufacturer:", error);
+ alert("An error occurred while deleting the manufacturer.");
+ }
+ finally {
+ this.loading = false;
+ }
+ },
}
+
});
$(function () {
diff --git a/Areas/Inventory/Views/_InventoryPartial.cshtml b/Areas/Inventory/Views/_InventoryPartial.cshtml
new file mode 100644
index 0000000..be28699
--- /dev/null
+++ b/Areas/Inventory/Views/_InventoryPartial.cshtml
@@ -0,0 +1,51 @@
+@addTagHelper *, Microsoft.AspNetCore.Mvc.TagHelpers
+
\ No newline at end of file
diff --git a/Controllers/API/Inventory/InvMainAPI.cs b/Controllers/API/Inventory/InvMainAPI.cs
index 3f2e0a5..3613946 100644
--- a/Controllers/API/Inventory/InvMainAPI.cs
+++ b/Controllers/API/Inventory/InvMainAPI.cs
@@ -39,7 +39,7 @@ namespace PSTW_CentralSystem.Controllers.API.Inventory
}
if (manufacturer == null)
{
- return BadRequest("Manufacturer is null");
+ return NotFound("Manufacturer is null");
}
try
@@ -58,5 +58,20 @@ namespace PSTW_CentralSystem.Controllers.API.Inventory
}
}
+ [HttpDelete("DeleteManufacturer/{id}")]
+ public async Task
DeleteManufacturer(int id)
+ {
+ var manufacturer = await _authDbContext.Manufacturers.FindAsync(id);
+ if (manufacturer == null)
+ {
+ return NotFound(new { success = false, message = "Manufacturer not found" });
+ }
+
+ _authDbContext.Manufacturers.Remove(manufacturer);
+ await _authDbContext.SaveChangesAsync();
+
+ return Ok(new { success = true, message = "Manufacturer deleted successfully" });
+ }
+
}
}
diff --git a/Controllers/API/ModuleAPI.cs b/Controllers/API/ModuleAPI.cs
index ec7d77d..558064c 100644
--- a/Controllers/API/ModuleAPI.cs
+++ b/Controllers/API/ModuleAPI.cs
@@ -1,6 +1,8 @@
using Microsoft.AspNetCore.Mvc;
using Microsoft.EntityFrameworkCore;
+using PSTW_CentralSystem.Areas.Inventory.Models;
using PSTW_CentralSystem.DBContext;
+using PSTW_CentralSystem.Models;
namespace PSTW_CentralSystem.Controllers.API
{
@@ -29,5 +31,30 @@ namespace PSTW_CentralSystem.Controllers.API
var qcList = await _authDbContext.ModuleSettings.Where(x => x.SettingId == id).FirstOrDefaultAsync();
return Json(qcList);
}
+
+ [HttpPost("AddModule")]
+ public async Task AddModule([FromBody] ModuleSettingModel module)
+ {
+ if (!ModelState.IsValid)
+ {
+ return BadRequest(ModelState);
+ }
+ if (module == null)
+ {
+ return NotFound("Module is null");
+ }
+
+ try
+ {
+ _authDbContext.ModuleSettings.Add(module);
+ await _authDbContext.SaveChangesAsync();
+ var updatedList = await _authDbContext.ModuleSettings.ToListAsync();
+ return Json(updatedList);
+ }
+ catch (Exception ex)
+ {
+ return BadRequest(ex.Message);
+ }
+ }
}
}