From 8b452c2bbdfa67d00d4ba5cb1b30c6b80e360402 Mon Sep 17 00:00:00 2001 From: Mohaimen Hasan Date: Mon, 16 Nov 2026 18:00:21 +0600 Subject: [PATCH] Role Permission --- HRM.DA/Service/Users/RoleService.cs | 12 ++---------- HRM.UI/Controllers/Auth/AuthController.cs | 7 ------- 2 files changed, 2 insertions(+), 17 deletions(-) diff --git a/HRM.DA/Service/Users/RoleService.cs b/HRM.DA/Service/Users/RoleService.cs index e30b6e3..600aed5 100644 --- a/HRM.DA/Service/Users/RoleService.cs +++ b/HRM.DA/Service/Users/RoleService.cs @@ -329,16 +329,12 @@ namespace HRM.DA public int Save(Role oRole) { TransactionContext tc = null; - - try { tc = TransactionContext.Begin(true); - // Audit of the permission rows, by PermissionCode, read before they are deleted and // re-inserted below, so each kept menu keeps who/when it was created and approved. Dictionary existingPermissions = new Dictionary(); - if (oRole.IsNew) { int id = tc.GenerateID("Role", "RoleID"); @@ -361,11 +357,10 @@ namespace HRM.DA RoleDA.Update(tc, oRole); #region Delete Children RoleDA.Delete(tc, "RolePermission", "RoleID", oRole.ID); - // RoleDA.Delete(tc, "Role.RoleActionPermission", "RoleID", oRole.ID); - // RoleDA.Delete(tc, "RoleDesignation", "RoleID", oRole.ID); + //RoleDA.Delete(tc, "Role.RoleActionPermission", "RoleID", oRole.ID); + //RoleDA.Delete(tc, "RoleDesignation", "RoleID", oRole.ID); #endregion } - if (oRole.RolePermissions != null & oRole.RolePermissions.Count > 0) { int maxID = oRole.RolePermissions.Max(x => x.ID); @@ -389,15 +384,12 @@ namespace HRM.DA // Whoever made this change: the editor, or the creator for a new role. On approval // the controller keeps the maker in ModifiedBy, so this is still the maker. int makerID = (oRole.ModifiedBy ?? 0) > 0 ? oRole.ModifiedBy.Value : oRole.CreatedBy; - foreach (Role.RolePermission rolePermission in oRole.RolePermissions) { rolePermission.RoleID = oRole.ID; - Role.RolePermission existingPermission = null; if (rolePermission.PermissionCode != null) existingPermissions.TryGetValue(rolePermission.PermissionCode, out existingPermission); - if (existingPermission != null) { // Menu the role already had: keep its original audit. diff --git a/HRM.UI/Controllers/Auth/AuthController.cs b/HRM.UI/Controllers/Auth/AuthController.cs index 648124b..2f47b59 100644 --- a/HRM.UI/Controllers/Auth/AuthController.cs +++ b/HRM.UI/Controllers/Auth/AuthController.cs @@ -1307,17 +1307,12 @@ namespace HRM.UI.Controllers } role.RoleStatus = EnumAuthStatus.EditedNotYetApprove; } - - // The browser sends createdBy 0 on edit/approve; use the real creator (RoleDA.Update - // does not write it, it is only used for the permission rows' audit). role.CreatedBy = existingRole.CreatedBy; role.CreatedDate = existingRole.CreatedDate; role.ApproveDate = null; role.ApproveBy = null; if (role.RoleStatus == EnumAuthStatus.Approved) { - // Approval keeps the maker (who made the change) on the role; the approver is - // recorded separately in ApproveBy / ApproveDate below. role.ModifiedBy = existingRole.ModifiedBy; role.ModifiedDate = existingRole.ModifiedDate; } @@ -1327,13 +1322,11 @@ namespace HRM.UI.Controllers role.ModifiedDate = DateTime.Now; } } - if (role.RoleStatus == EnumAuthStatus.Approved) { role.ApproveDate = DateTime.Today; role.ApproveBy = currentUser.UserID; } - id = this._roleService.Save(role); } catch (Exception e)