This commit is contained in:
MOHD ARIFF 2024-11-26 10:50:50 +08:00
parent b6b8b4a705
commit d7e93a98b3
6 changed files with 169 additions and 75 deletions

View File

@ -9,53 +9,4 @@
<p>Learn about <a href="https://learn.microsoft.com/aspnet/core">building Web apps with ASP.NET Core</a>.</p> <p>Learn about <a href="https://learn.microsoft.com/aspnet/core">building Web apps with ASP.NET Core</a>.</p>
</div> </div>
</div> </div>
<div class="row"> @await Html.PartialAsync("~/Areas/Inventory/Views/_InventoryPartial.cshtml");
<div class="col-md-6 col-lg-3">
<a href="@Url.Action("ProductRegistration", "Item", new { area = "Inventory" })">
<div class="card card-hover">
<div class="box bg-cyan text-center">
<h1 class="font-light text-white">
<i class="mdi mdi-view-dashboard"></i>
</h1>
<h6 class="text-white">Product Registration</h6>
</div>
</div>
</a>
</div>
<div class="col-md-6 col-lg-3">
<div class="card card-hover">
<a asp-area="Inventory" asp-controller="Item" asp-action="ItemRegistration">
<div class="box bg-success text-center">
<h1 class="font-light text-white">
<i class="mdi mdi-view-dashboard"></i>
</h1>
<h6 class="text-white">Register Item</h6>
</div>
</a>
</div>
</div>
<div class="col-md-6 col-lg-3">
<div class="card card-hover">
<a asp-area="Inventory" asp-controller="Main" asp-action="SupplierRegistration">
<div class="box bg-info text-center">
<h1 class="font-light text-white">
<i class="mdi mdi-view-dashboard"></i>
</h1>
<h6 class="text-white">Supplier Registration</h6>
</div>
</a>
</div>
</div>
<div class="col-md-6 col-lg-3">
<div class="card card-hover">
<a asp-area="Inventory" asp-controller="Main" asp-action="ManifacturerRegistration">
<div class="box bg-warning text-center">
<h1 class="font-light text-white">
<i class="mdi mdi-view-dashboard"></i>
</h1>
<h6 class="text-white">Manifacturer Registration</h6>
</div>
</a>
</div>
</div>
</div>

View File

@ -3,23 +3,12 @@
Layout = "~/Views/Shared/_Layout.cshtml"; Layout = "~/Views/Shared/_Layout.cshtml";
} }
@await Html.PartialAsync("~/Areas/Inventory/Views/_InventoryPartial.cshtml");
<div id="registerProduct"> <div id="registerProduct">
<form v-on:submit.prevent="addProduct" data-aos="fade-right"> <form v-on:submit.prevent="addProduct" data-aos="fade-right">
<div class="container register" data-aos="fade-right"> <div class="container register" data-aos="fade-right">
<div class="row" data-aos="fade-right"> <div class="row" data-aos="fade-right">
<div class="col-md-12">
@*Left Side*@
<div class="col-md-3 register-left">
<img src="https://media.licdn.com/dms/image/C4E03AQEJ_X-GwTi3xg/profile-displayphoto-shrink_200_200/0/1607307680517?e=2147483647&v=beta&t=UL8IX1nO9iqRxGrQrNZ1O_i4tpjnOVVecIktw-GB6QI" alt="" />
<h3>Welcome</h3>
<p>Registration Product! Click button to go Registration Item Page</p>
<a href="@Url.Action("ItemRegistration", "Item", new { area = "Inventory" })">Item Registration</a><br />
</div>
@*Right Side*@
<div class="col-md-9 register-right">
<div class="tab-content" id="myTabContent"> <div class="tab-content" id="myTabContent">
<div class="tab-pane fade show active" id="home" role="tabpanel" aria-labelledby="home-tab"> <div class="tab-pane fade show active" id="home" role="tabpanel" aria-labelledby="home-tab">
<h3 class="register-heading">REGISTRATION PRODUCT</h3> <h3 class="register-heading">REGISTRATION PRODUCT</h3>
@ -137,7 +126,7 @@
el: '#registerProduct', el: '#registerProduct',
data: { data: {
productName: null, productName: null,
manufacturer: '', manufacturer: null,
category: null, category: null,
modelNo: null, modelNo: null,
quantityProduct: null, quantityProduct: null,
@ -274,7 +263,29 @@
this.imageSrc = ''; this.imageSrc = '';
this.imageProduct = null; 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);
});
},
} }
}); });
</script> </script>

View File

@ -3,10 +3,11 @@
Layout = "~/Views/Shared/_Layout.cshtml"; Layout = "~/Views/Shared/_Layout.cshtml";
} }
@await Html.PartialAsync("~/Areas/Inventory/Views/_InventoryPartial.cshtml");
<div id="app"> <div id="app">
<button id="addManufacturerBtn col-md-3 m-1" class="btn btn-success"><i class="fa fa-plus"></i>&nbsp;Add Manufacturer</button>
<div class="row card"> <div class="row card">
<div class="card-header"> <div class="card-header">
<button id="addManufacturerBtn" class="btn btn-success col-md-3 m-1"><i class="fa fa-plus"></i>&nbsp;Add Manufacturer</button>
</div> </div>
<div class="card-body"> <div class="card-body">
<div v-if="loading"> <div v-if="loading">
@ -14,7 +15,7 @@
<span class="visually-hidden">Loading...</span> <span class="visually-hidden">Loading...</span>
</div> </div>
</div> </div>
<table class="table table-bordered table-hover table-striped" id="manufacturerTable"></table> <table class="table table-bordered table-hover" id="manufacturerTable"></table>
</div> </div>
</div> </div>
<div class="modal fade" id="addManufacturerModal" tabindex="-1" role="dialog" aria-labelledby="addManufacturerModalLabel" aria-hidden="true"> <div class="modal fade" id="addManufacturerModal" tabindex="-1" role="dialog" aria-labelledby="addManufacturerModalLabel" aria-hidden="true">
@ -96,13 +97,21 @@
}, },
{ "title": "Delete", { "title": "Delete",
"data": "manufacturerName", "data": "manufacturerName",
"render": function (data, type, full, meta) { "render": function (data, type, full, meta) {
var deleteButton = `<button type="button" class="btn btn-primary" @@click="deleteManufacturer(${manufacturerId})">Delete</button>`; var deleteButton = `<button type="button" class="btn btn-danger delete-btn" data-id="${full.manufacturerId}">Delete</button>`;
return 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; this.loading = false;
}, },
fillTable(data){ fillTable(data){
@ -145,10 +154,40 @@
this.newManufacturer.manufacturerName = null; this.newManufacturer.manufacturerName = null;
}); });
}, },
deleteManufacturer(Id){ async deleteManufacturer(manufacturerId) {
console.log(Id) 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 () { $(function () {

View File

@ -0,0 +1,51 @@
@addTagHelper *, Microsoft.AspNetCore.Mvc.TagHelpers
<div class="row">
<div class="col-md-6 col-lg-3">
<a href="@Url.Action("ProductRegistration", "Item", new { area = "Inventory" })">
<div class="card card-hover">
<div class="box bg-cyan text-center">
<h1 class="font-light text-white">
<i class="mdi mdi-view-dashboard"></i>
</h1>
<h6 class="text-white">Product Registration</h6>
</div>
</div>
</a>
</div>
<div class="col-md-6 col-lg-3">
<div class="card card-hover">
<a asp-area="Inventory" asp-controller="Item" asp-action="ItemRegistration">
<div class="box bg-success text-center">
<h1 class="font-light text-white">
<i class="mdi mdi-view-dashboard"></i>
</h1>
<h6 class="text-white">Register Item</h6>
</div>
</a>
</div>
</div>
<div class="col-md-6 col-lg-3">
<div class="card card-hover">
<a asp-area="Inventory" asp-controller="Main" asp-action="SupplierRegistration">
<div class="box bg-info text-center">
<h1 class="font-light text-white">
<i class="mdi mdi-view-dashboard"></i>
</h1>
<h6 class="text-white">Supplier Registration</h6>
</div>
</a>
</div>
</div>
<div class="col-md-6 col-lg-3">
<div class="card card-hover">
<a asp-area="Inventory" asp-controller="Main" asp-action="ManifacturerRegistration">
<div class="box bg-warning text-center">
<h1 class="font-light text-white">
<i class="mdi mdi-view-dashboard"></i>
</h1>
<h6 class="text-white">Manifacturer Registration</h6>
</div>
</a>
</div>
</div>
</div>

View File

@ -39,7 +39,7 @@ namespace PSTW_CentralSystem.Controllers.API.Inventory
} }
if (manufacturer == null) if (manufacturer == null)
{ {
return BadRequest("Manufacturer is null"); return NotFound("Manufacturer is null");
} }
try try
@ -58,5 +58,20 @@ namespace PSTW_CentralSystem.Controllers.API.Inventory
} }
} }
[HttpDelete("DeleteManufacturer/{id}")]
public async Task<IActionResult> 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" });
}
} }
} }

View File

@ -1,6 +1,8 @@
using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.Mvc;
using Microsoft.EntityFrameworkCore; using Microsoft.EntityFrameworkCore;
using PSTW_CentralSystem.Areas.Inventory.Models;
using PSTW_CentralSystem.DBContext; using PSTW_CentralSystem.DBContext;
using PSTW_CentralSystem.Models;
namespace PSTW_CentralSystem.Controllers.API 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(); var qcList = await _authDbContext.ModuleSettings.Where(x => x.SettingId == id).FirstOrDefaultAsync();
return Json(qcList); return Json(qcList);
} }
[HttpPost("AddModule")]
public async Task<IActionResult> 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);
}
}
} }
} }