From f8ef2b449cec28c3f75bb32c0a951d8c3682433a Mon Sep 17 00:00:00 2001 From: ArifHilmi Date: Wed, 19 Feb 2025 12:11:22 +0800 Subject: [PATCH] update station and request --- .../Admin/InventoryMasterController.cs | 5 + Areas/Inventory/Models/RequestModel.cs | 20 ++ .../StationRegistration.cshtml | 298 ++++++++++++++++++ .../SupplierRegistration.cshtml | 2 +- Controllers/API/IdentityAPI.cs | 40 +++ Controllers/API/Inventory/InvMainAPI.cs | 45 +++ DBContext/CentralSystemContext.cs | 1 + Views/Shared/_Layout.cshtml | 7 + 8 files changed, 417 insertions(+), 1 deletion(-) create mode 100644 Areas/Inventory/Models/RequestModel.cs create mode 100644 Areas/Inventory/Views/InventoryMaster/StationRegistration.cshtml diff --git a/Areas/Inventory/Controllers/Admin/InventoryMasterController.cs b/Areas/Inventory/Controllers/Admin/InventoryMasterController.cs index 69301e1..ac4d3a1 100644 --- a/Areas/Inventory/Controllers/Admin/InventoryMasterController.cs +++ b/Areas/Inventory/Controllers/Admin/InventoryMasterController.cs @@ -30,5 +30,10 @@ namespace PSTW_CentralSystem.Areas.Inventory.Controllers.Admin { return View(); } + + public IActionResult StationRegistration() + { + return View(); + } } } diff --git a/Areas/Inventory/Models/RequestModel.cs b/Areas/Inventory/Models/RequestModel.cs new file mode 100644 index 0000000..3480ed6 --- /dev/null +++ b/Areas/Inventory/Models/RequestModel.cs @@ -0,0 +1,20 @@ +using PSTW_CentralSystem.Models; +using System.ComponentModel.DataAnnotations; +using System.ComponentModel.DataAnnotations.Schema; +namespace PSTW_CentralSystem.Areas.Inventory.Models +{ + public class RequestModel + { + [Key] + public int requestId { get; set; } + public int DepartmentId { get; set; } + [ForeignKey("DepartmentId")] + public virtual ItemModel? Department { get; set; } + [ForeignKey("ItemID")] + public string? remark { get; set; } + public string? status { get; set; } + public DateTime requestDate { get; set; } + public DateTime approvalDate { get; set; } + + } +} diff --git a/Areas/Inventory/Views/InventoryMaster/StationRegistration.cshtml b/Areas/Inventory/Views/InventoryMaster/StationRegistration.cshtml new file mode 100644 index 0000000..5988894 --- /dev/null +++ b/Areas/Inventory/Views/InventoryMaster/StationRegistration.cshtml @@ -0,0 +1,298 @@ +@{ + ViewData["Title"] = "Station"; + Layout = "~/Views/Shared/_Layout.cshtml"; +} + +@await Html.PartialAsync("~/Areas/Inventory/Views/_InventoryPartial.cshtml"); +
+
+
+
+
+
+
+

REGISTRATION STATION

+
+
+ + @* Station Name *@ +
+ +
+ +
+
+ + @* User ID *@ +
+ +
+ +
+
+ + @* Department ID *@ + +
+ +
+ + {{ selectedDepartment }} + No department assigned +
+
+ + +
+
+
+ + +
+
+
+
+
+
+
+
+
+
+
+ +
+
+
+
+
+
+@section Scripts { + @{ + await Html.RenderPartialAsync("_ValidationScriptsPartial"); + } + +} \ No newline at end of file diff --git a/Areas/Inventory/Views/InventoryMaster/SupplierRegistration.cshtml b/Areas/Inventory/Views/InventoryMaster/SupplierRegistration.cshtml index 82e1712..422308b 100644 --- a/Areas/Inventory/Views/InventoryMaster/SupplierRegistration.cshtml +++ b/Areas/Inventory/Views/InventoryMaster/SupplierRegistration.cshtml @@ -107,7 +107,7 @@ supplierAddress : null, supplierPhoneNo : null, supplierPIC : null, - suuppliers: null, + suppliers: null, supplierDatatable: null, gender: ["Male", "Female", "Helicopter"], registerSupplierForm: false diff --git a/Controllers/API/IdentityAPI.cs b/Controllers/API/IdentityAPI.cs index 77d003c..f62d5ae 100644 --- a/Controllers/API/IdentityAPI.cs +++ b/Controllers/API/IdentityAPI.cs @@ -3,6 +3,7 @@ using Microsoft.AspNetCore.Mvc; using Microsoft.EntityFrameworkCore; using PSTW_CentralSystem.DBContext; using PSTW_CentralSystem.Models; +using System.Linq; using System.Security.Cryptography; using System.Text; using System.Text.Json; @@ -63,6 +64,45 @@ namespace PSTW_CentralSystem.Controllers.API return StatusCode(500, $"An error occurred: {ex.Message}"); } } + + [HttpPost("GetTechnicianUserInformation")] + public async Task GetTechnicianUserInformation() + { + try + { + var users = await _identityDbContext.Users + .Include(u => u.Department) + .ToListAsync(); // Retrieve all users with department info + + var technicianUsers = new List(); + + foreach (var user in users) + { + var roles = await _userManager.GetRolesAsync(user); + if (roles.Contains("Technician")) + { + technicianUsers.Add(new + { + id = user.Id, + fullname = user.FullName, + department = user.Department + }); + } + } + + if (!technicianUsers.Any()) + { + return NotFound(new { message = "No technicians found" }); + } + + return Ok(new { technicianUsers = technicianUsers }); + } + catch (Exception ex) + { + return StatusCode(500, new { message = $"An error occurred: {ex.Message}" }); + } + + } #endregion User #region LDAP Login diff --git a/Controllers/API/Inventory/InvMainAPI.cs b/Controllers/API/Inventory/InvMainAPI.cs index fa8de0c..940b8f9 100644 --- a/Controllers/API/Inventory/InvMainAPI.cs +++ b/Controllers/API/Inventory/InvMainAPI.cs @@ -610,5 +610,50 @@ namespace PSTW_CentralSystem.Controllers.API.Inventory } #endregion + + #region Station + [HttpPost("StationList")] + public async Task StationList() + { + var stationList = await _centralDbContext.Stations.ToListAsync(); + return Json(stationList); + } + + [HttpPost("AddStation")] + public async Task AddStation([FromBody] StationModel station) + { + if (!ModelState.IsValid) + { + return BadRequest(ModelState); + } + + try + { + _centralDbContext.Stations.Add(station); + await _centralDbContext.SaveChangesAsync(); + var updatedList = await _centralDbContext.Stations.ToListAsync(); + return Json(updatedList); + } + catch (Exception ex) + { + return BadRequest(ex.Message); + } + } + + [HttpDelete("DeleteStation/{id}")] + public async Task DeleteStation(int id) + { + var station = await _centralDbContext.Stations.FindAsync(id); + if (station == null) + { + return NotFound(new { success = false, message = "Station not found" }); + } + + _centralDbContext.Stations.Remove(station); + await _centralDbContext.SaveChangesAsync(); + + return Ok(new { success = true, message = "Station deleted successfully" }); + } + #endregion Station } } diff --git a/DBContext/CentralSystemContext.cs b/DBContext/CentralSystemContext.cs index a48815a..4811aa7 100644 --- a/DBContext/CentralSystemContext.cs +++ b/DBContext/CentralSystemContext.cs @@ -91,6 +91,7 @@ namespace PSTW_CentralSystem.DBContext public DbSet Departments { get; set; } public DbSet Manufacturers { get; set; } public DbSet Items { get; set; } + public DbSet Requests { get; set; } public DbSet Products { get; set; } public DbSet Suppliers { get; set; } public DbSet InventoryMasters { get; set; } diff --git a/Views/Shared/_Layout.cshtml b/Views/Shared/_Layout.cshtml index 17213b5..f9730df 100644 --- a/Views/Shared/_Layout.cshtml +++ b/Views/Shared/_Layout.cshtml @@ -454,6 +454,13 @@ Item Registration +