Beispiel #1
0
        public static RoleManagerByTab GetByRoleIdAndTabId(string Guid, int moduleId)
        {
            RoleManagerByTab manager = new RoleManagerByTab();

            manager.RoleId   = Guid;
            manager.ModuleId = moduleId;

            ApplicationDbContext db        = new ApplicationDbContext();
            List <int>           tabIdList = db.ASPNETROLESHTML
                                             .Where(s => s.MODULEID == moduleId &&
                                                    s.ROLEID == Guid &&
                                                    s.TABID != null)
                                             .Select(s => s.TABID.Value).Distinct().ToList();

            foreach (int tid in tabIdList)
            {
                HtmlRoleWithTab tab1      = new HtmlRoleWithTab();
                HtmlRole        tabHeader = HtmlRole.GetTabHeader(Guid, moduleId, tid);
                List <HtmlRole> roles     = HtmlRole.GetHtmlRolesWithSort(Guid, moduleId, tid);
                tab1.TabHeader = tabHeader;
                tab1.HtmlRoles = roles;
                manager.HtmlRolesWithTabs.Add(tab1);
            }

            List <HtmlRoleWithTab> sorted = manager
                                            .HtmlRolesWithTabs.OrderBy(s => s.TabHeader.TabId).ToList();

            manager.HtmlRolesWithTabs = sorted;
            return(manager);
        }
Beispiel #2
0
        //convert ASPNETROLESHTML kepada List<HtmlRole>
        //css-class kalau null, kita defaultkan valuenya ke "noclass"
        //display kat View
        public static List <HtmlRole> GetHtmlRoles(string roleId, int moduleId, int tabId = 0)
        {
            List <ASPNETROLESHTML> roles = new List <ASPNETROLESHTML>();

            if (tabId == 0)
            {
                roles = ASPNETROLESHTML.GetByRoleId(roleId);
            }
            else
            {
                roles = ASPNETROLESHTML.GetByRoleId(roleId, moduleId, tabId);
            }

            List <HtmlRole> output = new List <HtmlRole>();

            foreach (ASPNETROLESHTML role in roles)
            {
                HtmlRole single = new HtmlRole();
                single.RoleId   = role.ROLEID;
                single.ModuleId = role.MODULEID.Equals(DBNull.Value) ? 0 : moduleId;
                single.TabId    = role.TABID.Equals(DBNull.Value) ? 0 : tabId;
                single.HtmlName = role.HTMLNAME;
                single.CSSClass = role.CSSCLASS == null ? "noclass": role.CSSCLASS;

                if (!role.ISVIEW.Equals(DBNull.Value))
                {
                    if (role.ISVIEW > 0)
                    {
                        single.IsView = true;
                    }
                }
                if (!role.ISADD.Equals(DBNull.Value))
                {
                    if (role.ISADD > 0)
                    {
                        single.IsAdd = true;
                    }
                }
                if (!role.ISEDIT.Equals(DBNull.Value))
                {
                    if (role.ISEDIT > 0)
                    {
                        single.IsEdit = true;
                    }
                }
                if (!role.ISDELETE.Equals(DBNull.Value))
                {
                    if (role.ISDELETE > 0)
                    {
                        single.IsDelete = true;
                    }
                }

                output.Add(single);
            }
            return(output);
        }
Beispiel #3
0
        //testing
        #region TestData
        private static HtmlRole GetSampleRole(string htmlName, ViewLevel vl = ViewLevel.Edit)
        {
            HtmlRole role1 = new HtmlRole
            {
                RoleId   = ModuleConstant.roleAdmin,
                ModuleId = ModuleConstant.MaklumatKakiTangan,
                HtmlName = htmlName,
                IsView   = true,
                IsAdd    = false,
                IsEdit   = false,
                IsDelete = false
            };

            switch (vl)
            {
            case (ViewLevel.NoAccess):
                role1.IsView   = false;
                role1.IsAdd    = false;
                role1.IsEdit   = false;
                role1.IsDelete = false;
                break;

            case (ViewLevel.View):
                role1.IsView   = true;
                role1.IsAdd    = false;
                role1.IsEdit   = false;
                role1.IsDelete = false;
                break;

            case (ViewLevel.Add):
                role1.IsView   = true;
                role1.IsAdd    = true;
                role1.IsEdit   = false;
                role1.IsDelete = false;
                break;

            case (ViewLevel.Edit):
                role1.IsView   = true;
                role1.IsAdd    = false;
                role1.IsEdit   = true;
                role1.IsDelete = false;
                break;

            case (ViewLevel.Delete):
                role1.IsView   = true;
                role1.IsAdd    = false;
                role1.IsEdit   = false;
                role1.IsDelete = true;
                break;
            }

            return(role1);
        }
Beispiel #4
0
        //masa nak edit role je kita sort
        //masa nak search role nak display kat view, tak payah sort
        public static List <HtmlRole> GetHtmlRolesWithSort(string roleId, int moduleId, int tabId = 0)
        {
            List <HtmlRole> output = GetHtmlRoles(roleId, moduleId, tabId);
            HtmlRole        tab    = output.Where(s => s.CSSClass == "tab").FirstOrDefault();

            if (tab != null)
            {
                output.Remove(tab);
            }
            output = output.OrderBy(o => o.CSSClass).ToList();
            return(output);
        }
Beispiel #5
0
        public static RoleManager GetByRoleIdWithSort(string Guid, int moduleId, int tabId)
        {
            RoleManager manager = new RoleManager
            {
                RoleId   = Guid,
                ModuleId = moduleId
            };

            List <HtmlRole> roles = HtmlRole.GetHtmlRolesWithSort(Guid, moduleId, tabId);

            manager.HtmlRoles.AddRange(roles);

            return(manager);
        }
Beispiel #6
0
        //testing only
        private static RoleManager GetSample()
        {
            RoleManager rm = new RoleManager();

            rm.RoleId   = "4a205be5-cadc-446c-87c2-86c7ec5d6559";
            rm.ModuleId = ModuleConstant.MaklumatKakiTangan;
            List <HtmlRole> roles = HtmlRole.GetSampleList();

            foreach (HtmlRole role in roles)
            {
                role.ModuleId = rm.ModuleId;
            }
            rm.HtmlRoles.AddRange(roles);
            return(rm);
        }
Beispiel #7
0
        public static List <HtmlRole> GetSampleList()
        {
            HtmlRole role1  = GetSampleRole("key");
            HtmlRole role2  = GetSampleRole("value");
            HtmlRole role3  = GetSampleRole("search");
            HtmlRole role4  = GetSampleRole("HR_NAMA_PEKERJA");
            HtmlRole role5  = GetSampleRole("HR_NO_KPBARU");
            HtmlRole role18 = GetSampleRole("Pekerjaan");
            HtmlRole role6  = GetSampleRole("Kemahiran");
            HtmlRole role7  = GetSampleRole("Akademik", ViewLevel.View);
            HtmlRole role8  = GetSampleRole("Pewaris", ViewLevel.View);
            HtmlRole role9  = GetSampleRole("Tanggungan");
            HtmlRole role10 = GetSampleRole("Kuarters", ViewLevel.NoAccess);
            HtmlRole role11 = GetSampleRole("Gaji", ViewLevel.View);
            HtmlRole role12 = GetSampleRole("Anugerah");
            HtmlRole role13 = GetSampleRole("Persaraan", ViewLevel.NoAccess);
            HtmlRole role14 = GetSampleRole("Tatatertib", ViewLevel.NoAccess);
            HtmlRole role15 = GetSampleRole("Kematian", ViewLevel.NoAccess);
            HtmlRole role16 = GetSampleRole("Prestasi", ViewLevel.NoAccess);
            HtmlRole role17 = GetSampleRole("Cuti");
            HtmlRole edit1  = GetSampleRole("mKakitangan-btn");

            List <HtmlRole> htmlRoles = new List <HtmlRole>();

            htmlRoles.Add(role1);
            htmlRoles.Add(role2);
            htmlRoles.Add(role3);
            htmlRoles.Add(role4);
            htmlRoles.Add(role5);
            htmlRoles.Add(role6);
            htmlRoles.Add(role7);
            htmlRoles.Add(role8);
            htmlRoles.Add(role9);
            htmlRoles.Add(role10);
            htmlRoles.Add(role11);
            htmlRoles.Add(role12);
            htmlRoles.Add(role13);
            htmlRoles.Add(role14);
            htmlRoles.Add(role15);
            htmlRoles.Add(role16);
            htmlRoles.Add(role17);
            htmlRoles.Add(role18);
            htmlRoles.Add(edit1);

            htmlRoles = htmlRoles.OrderBy(o => o.HtmlName).ToList();
            return(htmlRoles);
        }
Beispiel #8
0
        public static HtmlRole GetTabHeader(string roleId, int moduleId, int tabId)
        {
            HtmlRole tabHeader = GetHtmlRoles(roleId, moduleId, tabId)
                                 .Where(s => s.CSSClass == "tab").FirstOrDefault();

            if (tabHeader == null)
            {
                tabHeader = new HtmlRole
                {
                    RoleId   = roleId,
                    ModuleId = moduleId,
                    HtmlName = "",
                    TabId    = tabId,
                    CSSClass = "tab",
                    IsView   = false,
                    IsAdd    = false,
                    IsEdit   = false,
                    IsDelete = false
                };
            }
            return(tabHeader);
        }
Beispiel #9
0
        public static HtmlRole GetHtmlRoleByHtmlName(List <HtmlRole> HtmlRoles, string htmlName, string RoleId, int ModuleId)
        {
            HtmlRole role = HtmlRoles
                            .Where(s => s.HtmlName == htmlName).FirstOrDefault();

            //kalau takde role dalam DB,
            //create satu temp Value yang takde access
            if (role == null)
            {
                role = new HtmlRole
                {
                    RoleId   = RoleId,
                    ModuleId = ModuleId,
                    HtmlName = htmlName,
                    CSSClass = "noclass",
                    IsView   = false,
                    IsAdd    = false,
                    IsEdit   = false,
                    IsDelete = false
                };
            }
            return(role);
        }
Beispiel #10
0
        public HtmlRole GetHtmlRole(string htmlName)
        {
            HtmlRole output = HtmlRole.GetHtmlRoleByHtmlName(HtmlRoles, htmlName, RoleId, ModuleId);

            return(output);
        }