diff --git a/Areas/Inventory/Controllers/ItemController.cs b/Areas/Inventory/Controllers/ItemController.cs index 403a41e..60019d1 100644 --- a/Areas/Inventory/Controllers/ItemController.cs +++ b/Areas/Inventory/Controllers/ItemController.cs @@ -1,6 +1,9 @@ using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Http; +using PSTW_CentralSystem.Models; +using Microsoft.AspNetCore.Identity; using Microsoft.AspNetCore.Mvc; +using System.Security.Claims; namespace PSTW_CentralSystem.Areas.Inventory.Controllers { @@ -9,44 +12,69 @@ namespace PSTW_CentralSystem.Areas.Inventory.Controllers //[Authorize(Policy = "RoleModulePolicy")] public class ItemController : Controller { + private readonly IHttpContextAccessor _httpContextAccessor; + + public ItemController(IHttpContextAccessor httpContextAccessor) + { + _httpContextAccessor = httpContextAccessor; + } + public string GetCurrentUserId() + { + var user = _httpContextAccessor.HttpContext?.User; + + if (user == null) + { + return null!; + } + + return user.FindFirstValue(ClaimTypes.NameIdentifier) ?? null!; // Returns the user ID + } + // GET: Inventory public ActionResult Index() { - return View(); + var userId = GetCurrentUserId(); + return View(userId); } public IActionResult ItemRegistration() { - return View(); + var userId = GetCurrentUserId(); + return View(userId); } public IActionResult ProductRegistration() { - return View(); + var userId = GetCurrentUserId(); + return View(userId); } // GET: Inventory/Details/5 public ActionResult Details(int id) { - return View(); + var userId = GetCurrentUserId(); + return View(userId); } // GET: Inventory/Create public ActionResult Create() { - return View(); + var userId = GetCurrentUserId(); + return View(userId); } // GET: Inventory/Edit/5 public ActionResult Edit(int id) { - return View(); + var userId = GetCurrentUserId(); + return View(userId); } // GET: Inventory/Delete/5 public ActionResult Delete(int id) { - return View(); + var userId = GetCurrentUserId(); + return View(userId); } } diff --git a/Areas/Inventory/Controllers/MainController.cs b/Areas/Inventory/Controllers/MainController.cs index 526809d..08aaa34 100644 --- a/Areas/Inventory/Controllers/MainController.cs +++ b/Areas/Inventory/Controllers/MainController.cs @@ -1,6 +1,7 @@ using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Mvc; +using System.Security.Claims; namespace PSTW_CentralSystem.Areas.Inventory.Controllers { @@ -8,43 +9,68 @@ namespace PSTW_CentralSystem.Areas.Inventory.Controllers //[Authorize(Policy = "RoleModulePolicy")] public class MainController : Controller { + private readonly IHttpContextAccessor _httpContextAccessor; + + public MainController(IHttpContextAccessor httpContextAccessor) + { + _httpContextAccessor = httpContextAccessor; + } + public string GetCurrentUserId() + { + var user = _httpContextAccessor.HttpContext?.User; + + if (user == null) + { + return null!; + } + + return user.FindFirstValue(ClaimTypes.NameIdentifier) ?? null!; // Returns the user ID + } + // GET: Inventory public ActionResult Index() { - return View(); + var userId = GetCurrentUserId(); + return View(userId); } public IActionResult SupplierRegistration() { - return View(); + var userId = GetCurrentUserId(); + return View(userId); } public IActionResult ManifacturerRegistration() { - return View(); + var userId = GetCurrentUserId(); + return View(userId); } // GET: Inventory/Details/5 public ActionResult Details(int id) { - return View(); + var userId = GetCurrentUserId(); + return View(userId); } // GET: Inventory/Create public ActionResult Create() { - return View(); + var userId = GetCurrentUserId(); + return View(userId); } // GET: Inventory/Edit/5 public ActionResult Edit(int id) { - return View(); + var userId = GetCurrentUserId(); + return View(userId); } // GET: Inventory/Delete/5 public ActionResult Delete(int id) { - return View(); + var userId = GetCurrentUserId(); + return View(userId); } } diff --git a/Areas/Inventory/Models/ItemModel.cs b/Areas/Inventory/Models/ItemModel.cs index 886fe4b..4a3e6b0 100644 --- a/Areas/Inventory/Models/ItemModel.cs +++ b/Areas/Inventory/Models/ItemModel.cs @@ -1,5 +1,8 @@ -using System.ComponentModel.DataAnnotations; +using System.ComponentModel; +using System.ComponentModel.DataAnnotations; using System.ComponentModel.DataAnnotations.Schema; +using Microsoft.EntityFrameworkCore; +using PSTW_CentralSystem.Models; namespace PSTW_CentralSystem.Areas.Inventory.Models { @@ -12,6 +15,7 @@ namespace PSTW_CentralSystem.Areas.Inventory.Models public required int DepartmentId { get; set; } public required int ProductId { get; set; } public required string? SerialNumber { get; set; } + public required string? TeamType { get; set; } public required int Quantity { get; set; } public required string Supplier { get; set; } public required DateTime PurchaseDate { get; set; } @@ -20,10 +24,19 @@ namespace PSTW_CentralSystem.Areas.Inventory.Models public required float PriceInRM { get; set; } public required float CurrencyRate { get; set; } public required float ConvertPrice { get; set; } - public required DateTime DODate { get; set; } + public string? DONo { get; set; } + public DateTime? DODate { get; set; } public required int Warranty { get; set; } public required DateTime EndWDate { get; set; } - public required DateTime InvoiceDate { get; set; } + public string? InvoiceNo { get; set; } + public DateTime? InvoiceDate { get; set; } + [Comment("1 = In stock; 2 = Item Moving; 3 = Item Out; 4 = Item Broken; 5 = Item Lost; 6 = Item Stolen; 7 = Item Damaged; 8 = Item Discarded; 9 = Item Destroyed; 10 = Item Finished;")] + public int ItemStatus { get; set; } = 1; + public string ItemLocation { get; set; } = string.Empty; + public int CreatedByUserId { get; set; } + + [ForeignKey("CreatedByUserId")] + public virtual UserModel? CreatedBy { get; set; } [ForeignKey("CompanyId")] public virtual CompanyModel? Company { get; set; } [ForeignKey("DepartmentId")] diff --git a/Areas/Inventory/Models/StoreModel.cs b/Areas/Inventory/Models/StoreModel.cs new file mode 100644 index 0000000..3482b00 --- /dev/null +++ b/Areas/Inventory/Models/StoreModel.cs @@ -0,0 +1,6 @@ +namespace PSTW_CentralSystem.Areas.Inventory.Models +{ + public class StoreModel + { + } +} diff --git a/Areas/Inventory/Views/Item/ItemRegistration.cshtml b/Areas/Inventory/Views/Item/ItemRegistration.cshtml index e25149c..0903cfd 100644 --- a/Areas/Inventory/Views/Item/ItemRegistration.cshtml +++ b/Areas/Inventory/Views/Item/ItemRegistration.cshtml @@ -2,8 +2,9 @@ @{ ViewData["Title"] = "Item Form"; Layout = "~/Views/Shared/_Layout.cshtml"; - + string userId = ViewBag.UserId; } +