Role Permission
This commit is contained in:
parent
83b5935846
commit
8b452c2bbd
|
|
@ -329,16 +329,12 @@ namespace HRM.DA
|
||||||
public int Save(Role oRole)
|
public int Save(Role oRole)
|
||||||
{
|
{
|
||||||
TransactionContext tc = null;
|
TransactionContext tc = null;
|
||||||
|
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
tc = TransactionContext.Begin(true);
|
tc = TransactionContext.Begin(true);
|
||||||
|
|
||||||
// Audit of the permission rows, by PermissionCode, read before they are deleted and
|
// 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.
|
// re-inserted below, so each kept menu keeps who/when it was created and approved.
|
||||||
Dictionary<string, Role.RolePermission> existingPermissions = new Dictionary<string, Role.RolePermission>();
|
Dictionary<string, Role.RolePermission> existingPermissions = new Dictionary<string, Role.RolePermission>();
|
||||||
|
|
||||||
if (oRole.IsNew)
|
if (oRole.IsNew)
|
||||||
{
|
{
|
||||||
int id = tc.GenerateID("Role", "RoleID");
|
int id = tc.GenerateID("Role", "RoleID");
|
||||||
|
|
@ -361,11 +357,10 @@ namespace HRM.DA
|
||||||
RoleDA.Update(tc, oRole);
|
RoleDA.Update(tc, oRole);
|
||||||
#region Delete Children
|
#region Delete Children
|
||||||
RoleDA.Delete(tc, "RolePermission", "RoleID", oRole.ID);
|
RoleDA.Delete(tc, "RolePermission", "RoleID", oRole.ID);
|
||||||
// RoleDA.Delete(tc, "Role.RoleActionPermission", "RoleID", oRole.ID);
|
//RoleDA.Delete(tc, "Role.RoleActionPermission", "RoleID", oRole.ID);
|
||||||
// RoleDA.Delete(tc, "RoleDesignation", "RoleID", oRole.ID);
|
//RoleDA.Delete(tc, "RoleDesignation", "RoleID", oRole.ID);
|
||||||
#endregion
|
#endregion
|
||||||
}
|
}
|
||||||
|
|
||||||
if (oRole.RolePermissions != null & oRole.RolePermissions.Count > 0)
|
if (oRole.RolePermissions != null & oRole.RolePermissions.Count > 0)
|
||||||
{
|
{
|
||||||
int maxID = oRole.RolePermissions.Max(x => x.ID);
|
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
|
// 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.
|
// the controller keeps the maker in ModifiedBy, so this is still the maker.
|
||||||
int makerID = (oRole.ModifiedBy ?? 0) > 0 ? oRole.ModifiedBy.Value : oRole.CreatedBy;
|
int makerID = (oRole.ModifiedBy ?? 0) > 0 ? oRole.ModifiedBy.Value : oRole.CreatedBy;
|
||||||
|
|
||||||
foreach (Role.RolePermission rolePermission in oRole.RolePermissions)
|
foreach (Role.RolePermission rolePermission in oRole.RolePermissions)
|
||||||
{
|
{
|
||||||
rolePermission.RoleID = oRole.ID;
|
rolePermission.RoleID = oRole.ID;
|
||||||
|
|
||||||
Role.RolePermission existingPermission = null;
|
Role.RolePermission existingPermission = null;
|
||||||
if (rolePermission.PermissionCode != null)
|
if (rolePermission.PermissionCode != null)
|
||||||
existingPermissions.TryGetValue(rolePermission.PermissionCode, out existingPermission);
|
existingPermissions.TryGetValue(rolePermission.PermissionCode, out existingPermission);
|
||||||
|
|
||||||
if (existingPermission != null)
|
if (existingPermission != null)
|
||||||
{
|
{
|
||||||
// Menu the role already had: keep its original audit.
|
// Menu the role already had: keep its original audit.
|
||||||
|
|
|
||||||
|
|
@ -1307,17 +1307,12 @@ namespace HRM.UI.Controllers
|
||||||
}
|
}
|
||||||
role.RoleStatus = EnumAuthStatus.EditedNotYetApprove;
|
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.CreatedBy = existingRole.CreatedBy;
|
||||||
role.CreatedDate = existingRole.CreatedDate;
|
role.CreatedDate = existingRole.CreatedDate;
|
||||||
role.ApproveDate = null;
|
role.ApproveDate = null;
|
||||||
role.ApproveBy = null;
|
role.ApproveBy = null;
|
||||||
if (role.RoleStatus == EnumAuthStatus.Approved)
|
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.ModifiedBy = existingRole.ModifiedBy;
|
||||||
role.ModifiedDate = existingRole.ModifiedDate;
|
role.ModifiedDate = existingRole.ModifiedDate;
|
||||||
}
|
}
|
||||||
|
|
@ -1327,13 +1322,11 @@ namespace HRM.UI.Controllers
|
||||||
role.ModifiedDate = DateTime.Now;
|
role.ModifiedDate = DateTime.Now;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (role.RoleStatus == EnumAuthStatus.Approved)
|
if (role.RoleStatus == EnumAuthStatus.Approved)
|
||||||
{
|
{
|
||||||
role.ApproveDate = DateTime.Today;
|
role.ApproveDate = DateTime.Today;
|
||||||
role.ApproveBy = currentUser.UserID;
|
role.ApproveBy = currentUser.UserID;
|
||||||
}
|
}
|
||||||
|
|
||||||
id = this._roleService.Save(role);
|
id = this._roleService.Save(role);
|
||||||
}
|
}
|
||||||
catch (Exception e)
|
catch (Exception e)
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user