426 lines
15 KiB
C#
426 lines
15 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Data;
|
|
using System.Linq;
|
|
using Ease.Core;
|
|
|
|
namespace HRM.BO
|
|
{
|
|
public class Role : BasicBaseObject
|
|
{
|
|
#region Constructor
|
|
|
|
public Role()
|
|
{
|
|
Code = string.Empty;
|
|
Name = string.Empty;
|
|
ApproveBy = 0;
|
|
ApproveDate = DateTime.MinValue;
|
|
RoleStatus = EnumAuthStatus.Approved;
|
|
ModifiedBy = 0;
|
|
ModifiedDate = DateTime.MinValue;
|
|
RolePermissions = new List<RolePermission>();
|
|
_RoleActionPermission = new List<RoleActionPermission>();
|
|
}
|
|
|
|
#endregion
|
|
|
|
#region Properties
|
|
public string Name { get; set; }
|
|
public string Code { get; set; }
|
|
public string Description { get; set; }
|
|
public int? ApproveBy { get; set; }
|
|
public DateTime? ApproveDate { get; set; }
|
|
public EnumRoleType RoleType { get; set; }
|
|
public EnumAuthStatus RoleStatus { get; set; }
|
|
public List<RolePermission> RolePermissions { get; set; }
|
|
public List<RoleActionPermission> _RoleActionPermission { get; set; }
|
|
|
|
#region Child Objects
|
|
public class RoleActionPermission : AuditTrailBase
|
|
{
|
|
public RoleActionPermission()
|
|
{
|
|
RoleID = 0;
|
|
Name = string.Empty;
|
|
Status = EnumAuthStatus.NewNotYetApprove;
|
|
ApproveBy = 0;
|
|
ApproveDate = DateTime.MinValue;
|
|
ModifiedBy = 0;
|
|
ModifiedDate = DateTime.MinValue;
|
|
}
|
|
|
|
public int RoleID { get; set; }
|
|
public int RolePermissionID { get; set; }
|
|
public string ActionCode { get; set; }
|
|
public string Name { get; set; }
|
|
public string Url { get; set; }
|
|
|
|
public EnumAuthStatus Status { get; set; }
|
|
public int? ApproveBy { get; set; }
|
|
public DateTime? ApproveDate { get; set; }
|
|
|
|
}
|
|
|
|
public class RolePermission : AuditTrailBase
|
|
{
|
|
|
|
#region Constructor
|
|
|
|
public RolePermission()
|
|
{
|
|
RoleID = 0;
|
|
PermissionCode = string.Empty;
|
|
Name = string.Empty;
|
|
Link = string.Empty;
|
|
Status = EnumAuthStatus.None;
|
|
ApproveBy = 0;
|
|
ApproveDate = DateTime.MinValue;
|
|
ModifiedBy = 0;
|
|
ModifiedDate = DateTime.MinValue;
|
|
_RoleActionPermission = new List<RoleActionPermission>();
|
|
}
|
|
|
|
#endregion
|
|
|
|
#region Properties
|
|
public int RoleID { get; set; }
|
|
public string PermissionCode { get; set; }
|
|
public string Name { get; set; }
|
|
public string Link { get; set; }
|
|
public string Icon { get; set; }
|
|
public EnumAuthStatus Status { get; set; }
|
|
public int? ApproveBy { get; set; }
|
|
public DateTime? ApproveDate { get; set; }
|
|
public int? parentID {get;set;}
|
|
public List<RoleActionPermission> _RoleActionPermission { get; set; }
|
|
public List<RolePermission> Roles { get; set; }
|
|
public EnumRoleType RoleType { get; set; }
|
|
public bool isBookmarked { get; set; }
|
|
|
|
public static EnumRoleType GetRoletype(string sroleType)
|
|
{
|
|
EnumRoleType roltype = EnumRoleType.Admin;
|
|
switch (sroleType.ToLower())
|
|
{
|
|
case "admin":
|
|
roltype = EnumRoleType.Admin;
|
|
break;
|
|
case "ess":
|
|
case "web":
|
|
roltype = EnumRoleType.Self_Service;
|
|
break;
|
|
case "mobile":
|
|
roltype = EnumRoleType.Mobile;
|
|
break;
|
|
|
|
|
|
default:
|
|
roltype = EnumRoleType.Admin;
|
|
break;
|
|
}
|
|
|
|
return roltype;
|
|
}
|
|
|
|
#endregion
|
|
|
|
}
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
|
|
#endregion
|
|
}
|
|
|
|
public class WebMenuHead
|
|
{
|
|
public WebMenuHead() { }
|
|
|
|
public WebMenuHead(string smenuCode, string Level)
|
|
{
|
|
this.menuCode = smenuCode;
|
|
this.label = Level;
|
|
this.items = null;
|
|
this.icon = "pi pi-fw pi-sitemap";
|
|
}
|
|
public WebMenuHead(string smenuCode, string Level, string RouterLink)
|
|
{
|
|
this.menuCode = smenuCode;
|
|
this.label = Level;
|
|
this.routerLink = RouterLink;
|
|
this.items = null;
|
|
this.icon = "pi pi-fw pi-th-large";
|
|
}
|
|
public string menuCode { get; set; }
|
|
public string label { get; set; }
|
|
public string icon { get; set; }
|
|
public List<WebMenuGroup> items { get; set; }
|
|
public string routerLink { get; set; }
|
|
}
|
|
|
|
public class WebMenuGroup : IWebMenuEntry
|
|
{
|
|
public WebMenuGroup() { }
|
|
public WebMenuGroup(string smenuCode, string Level, string RouterLink)
|
|
{
|
|
this.menuCode = smenuCode;
|
|
this.label = Level;
|
|
this.routerLink = RouterLink;
|
|
this.items = null;
|
|
this.icon = "pi pi-fw pi-sign-in";
|
|
}
|
|
public WebMenuGroup(string smenuCode, string Level)
|
|
{
|
|
this.menuCode = smenuCode;
|
|
this.label = Level;
|
|
this.items = null;
|
|
this.icon = "pi pi-fw pi-sign-in";
|
|
}
|
|
|
|
public string uniqueName { get; set; }
|
|
public string label { get; set; }
|
|
public string routerLink { get; set; }
|
|
public string icon { get; set; }
|
|
public bool dividerAfter { get; set; }
|
|
public List<WebMenuItem> items { get; set; }
|
|
public string menuCode { get; set; }
|
|
}
|
|
|
|
public class WebMenuItem : IWebMenuEntry
|
|
{
|
|
public WebMenuItem() { }
|
|
public WebMenuItem(string smenuCode, string Level, string RouterLink)
|
|
{
|
|
this.menuCode = smenuCode;
|
|
this.label = Level;
|
|
this.routerLink = RouterLink;
|
|
this.icon = "pi pi-fw pi-th-large";
|
|
}
|
|
|
|
public string uniqueName { get; set; }
|
|
public string label { get; set; }
|
|
public string routerLink { get; set; }
|
|
public string icon { get; set; }
|
|
public bool dividerAfter { get; set; }
|
|
public string menuCode { get; set; }
|
|
public List<WebMenuItemDetail> items { get; set; }
|
|
}
|
|
|
|
public class WebMenuItemDetail
|
|
{
|
|
public WebMenuItemDetail() { }
|
|
public WebMenuItemDetail(string Level, string RouterLink)
|
|
{
|
|
this.label = Level;
|
|
this.routerLink = RouterLink;
|
|
this.icon = "pi pi-fw pi-th-large";
|
|
}
|
|
public WebMenuItemDetail(string smenuCode, string Level, string RouterLink)
|
|
{
|
|
this.menuCode = smenuCode;
|
|
this.label = Level;
|
|
this.routerLink = RouterLink;
|
|
this.icon = "pi pi-fw pi-th-large";
|
|
}
|
|
|
|
public string uniqueName { get; set; }
|
|
public string label { get; set; }
|
|
public string routerLink { get; set; }
|
|
public string icon { get; set; }
|
|
public string menuCode { get; set; }
|
|
}
|
|
|
|
/// <summary>
|
|
/// Menu display order/dividers per menu Key (Menu.xml Key = RolePermission.PermissionCode = WebMenu*.menuCode).
|
|
/// Icons are no longer hardcoded here - they come from RolePermission.Icon (Menu.xml's menuIcon
|
|
/// attribute, see RoleService.GetRolePermissionbyUserID), falling back to each WebMenu* type's own
|
|
/// default icon (different for a parent node vs. a child node) when the DB has none.
|
|
/// </summary>
|
|
public static class WebMenuStyle
|
|
{
|
|
// Display order and grouping of a parent's children, as in the GoHR menu design.
|
|
// A divider line is drawn between groups; children not listed keep their order after the listed ones.
|
|
private static readonly Dictionary<string, string[][]> _layouts = new Dictionary<string, string[][]>
|
|
{
|
|
{
|
|
"19", new[] // Me
|
|
{
|
|
new[] { "19.1", "19.2", "19.3" }, // Profile
|
|
new[] { "19.4", "19.5", "19.6", "19.7", "19.8" }, // Leave & attendance
|
|
new[] { "19.9", "19.10", "19.11" }, // Performance & development
|
|
new[] { "19.13", "19.14", "19.12" }, // Pay & requests
|
|
new[] { "19.15" }, // Separation
|
|
}
|
|
},
|
|
{
|
|
"19.12", new[] // Me > Payroll
|
|
{
|
|
new[] { "19.12.1", "19.12.2", "19.12.4", "19.12.5" }, // Statements
|
|
new[] { "19.12.3", "19.12.7", "19.12.6", "19.12.9", "19.12.8" },// Tax
|
|
}
|
|
},
|
|
};
|
|
|
|
/// <summary>
|
|
/// Reorders the children of a parent per its layout and sets dividerAfter between groups.
|
|
/// Groups are compared on the children actually present, so a missing permission doesn't lose a divider.
|
|
/// </summary>
|
|
public static void Arrange<T>(string parentCode, List<T> children) where T : IWebMenuEntry
|
|
{
|
|
if (parentCode == null || children == null || !_layouts.TryGetValue(parentCode, out string[][] groups))
|
|
return;
|
|
|
|
var positions = new Dictionary<string, (int group, int index)>();
|
|
for (int g = 0; g < groups.Length; g++)
|
|
for (int i = 0; i < groups[g].Length; i++)
|
|
positions[groups[g][i]] = (g, i);
|
|
|
|
(int group, int index) Position(T child) =>
|
|
child.menuCode != null && positions.TryGetValue(child.menuCode, out var p) ? p : (int.MaxValue, 0);
|
|
|
|
var ordered = children.OrderBy(Position).ToList();
|
|
children.Clear();
|
|
children.AddRange(ordered);
|
|
|
|
for (int i = 0; i < children.Count; i++)
|
|
{
|
|
int group = Position(children[i]).group;
|
|
int nextGroup = i + 1 < children.Count ? Position(children[i + 1]).group : group;
|
|
children[i].dividerAfter = group != nextGroup && nextGroup != int.MaxValue;
|
|
}
|
|
}
|
|
}
|
|
|
|
public interface IWebMenuEntry
|
|
{
|
|
string menuCode { get; }
|
|
bool dividerAfter { get; set; }
|
|
}
|
|
|
|
public class WebMenu
|
|
{
|
|
//private static List<WebMenuHead> _menus;
|
|
//public static List<WebMenuHead> Menus => _menus ?? (_menus = CreateMenu());
|
|
|
|
private List<WebMenuHead> _AdminMenus;
|
|
public List<WebMenuHead> AdminMenus => _AdminMenus ?? (_AdminMenus = AdminCreateMenu());
|
|
|
|
private static List<WebMenuHead> AdminCreateMenu()
|
|
{
|
|
|
|
return new List<WebMenuHead>()
|
|
{
|
|
new WebMenuHead()
|
|
{
|
|
label = "",
|
|
icon = "pi pi-fw pi-sitemap",
|
|
items = new List<WebMenuGroup>()
|
|
{
|
|
new WebMenuGroup()
|
|
{
|
|
uniqueName = "Dashboard.01",
|
|
label = "Home",
|
|
icon = "pi pi-fw pi-home",
|
|
items = null
|
|
},
|
|
new WebMenuGroup()
|
|
{
|
|
|
|
|
|
uniqueName = "WEB.01",
|
|
label = "Administration",
|
|
icon = "pi pi-fw pi-cog",
|
|
items = new List<WebMenuItem>()
|
|
{
|
|
new WebMenuItem()
|
|
{
|
|
uniqueName = "WEB.01.01",
|
|
label = "Configuration",
|
|
routerLink = "/authentication/configuration",
|
|
icon = "pi pi-fw pi-sliders-h",
|
|
|
|
},
|
|
new WebMenuItem()
|
|
{
|
|
uniqueName = "WEB.01.02",
|
|
label = "Role",
|
|
routerLink = "/authentication/role",
|
|
icon = "pi pi-fw pi-shield",
|
|
},
|
|
new WebMenuItem()
|
|
{
|
|
uniqueName = "WEB.01.03",
|
|
label = "User",
|
|
routerLink = "/authentication/user",
|
|
icon = "pi pi-fw pi-user",
|
|
},
|
|
new WebMenuItem()
|
|
{
|
|
uniqueName = "WEB.01.04",
|
|
label = "User Role Permission",
|
|
routerLink = "/authentication/user-role",
|
|
icon = "pi pi-fw pi-key",
|
|
},
|
|
new WebMenuItem()
|
|
{
|
|
uniqueName = "WEB.01.05",
|
|
label = "User Access Type",
|
|
routerLink = "/authentication/user-access-type",
|
|
icon = "pi pi-fw pi-id-card",
|
|
},
|
|
//new WebMenuItem()
|
|
//{
|
|
// uniqueName = "WEB.01.06",
|
|
// label = "Hard Password Setup",
|
|
// routerLink = "/authentication/hard-password",
|
|
//},
|
|
new WebMenuItem()
|
|
{
|
|
uniqueName = "WEB.01.07",
|
|
label = "Change Password",
|
|
routerLink = "/authentication/change-password",
|
|
icon = "pi pi-fw pi-lock",
|
|
}
|
|
,
|
|
new WebMenuItem()
|
|
{
|
|
uniqueName = "WEB.01.08",
|
|
label = "Data Permission",
|
|
routerLink = "/authentication/data-permssion",
|
|
icon = "pi pi-fw pi-database",
|
|
},
|
|
new WebMenuItem()
|
|
{
|
|
uniqueName = "WEB.01.08",
|
|
label = "Audit log",
|
|
routerLink = "/authentication/system-auditlog",
|
|
icon = "pi pi-fw pi-database",
|
|
},
|
|
}
|
|
},
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
};
|
|
}
|
|
}
|
|
public interface IRoleService
|
|
{
|
|
Role Get(int id);
|
|
List<Role> GetAllRole();
|
|
int Save(Role item);
|
|
void Delete(int id);
|
|
List<WebMenuHead> GetRolePermissionbyUserID(int Userid);
|
|
|
|
}
|
|
|
|
}
|