Пример #1
0
        //public static List<SelectListItem> LoadReligions()
        //{
        //    using (KDMDB db = new KDMDB())
        //    {
        //        var items = db.tbl_religions.Select(x => x).ToList();
        //        List<SelectListItem> selectItems = new List<SelectListItem>();

        //        foreach (var item in items)
        //        {
        //            selectItems.Add(new SelectListItem()
        //            {
        //                Value = item.Value,
        //                Text = item.Text
        //            });
        //        }
        //        return selectItems;
        //    }

        //}

        //public static string GetReligion(string value)
        //{
        //    using (KDMDB db = new KDMDB())
        //    {
        //        var item = db.tbl_religions.Where(x => x.Value == value).Select(x => x.Text).FirstOrDefault();

        //        return item;
        //    }
        //}

        //public static List<SelectListItem> LoadShifts()
        //{
        //    using (ERPSolution.Areas.HRPayroll.Models.HRPayrollDB db = new ERPSolution.Areas.HRPayroll.Models.HRPayrollDB())
        //    {
        //        var items = db.hr_liv_sft_conf_shift_time.Select(x => x).ToList();
        //        List<SelectListItem> selectItems = new List<SelectListItem>();

        //        foreach (var item in items)
        //        {
        //            selectItems.Add(new SelectListItem()
        //            {
        //                Value = item.ID.ToString(),
        //                Text = item.ShiftCode
        //            });
        //        }
        //        return selectItems;
        //    }

        //}

        //public static string GetShift(int value)
        //{
        //    using (ERPSolution.Areas.HRPayroll.Models.HRPayrollDB db = new ERPSolution.Areas.HRPayroll.Models.HRPayrollDB())
        //    {
        //        var item = db.hr_liv_sft_conf_shift_time.Where(x => x.ID == value).Select(x => x.ShiftCode).FirstOrDefault();

        //        return item;
        //    }
        //}

        public static List <MenuCategory> LoadMenu()
        {
            List <MenuItem>     items             = new List <MenuItem>();
            string              userId            = HttpContext.Current.User.Identity.GetUserId();
            IdentityManager     im                = new IdentityManager();
            List <string>       roles             = im.GetUsersRole(userId);
            List <MenuItem>     selectedMenuItems = new List <MenuItem>();
            List <MenuCategory> categories        = new List <MenuCategory>();

            using (KDMDB db = new KDMDB())
            {
                items = (from rw in db.tbl_RoleActionMappings
                         where roles.Contains(rw.Role) && rw.IsActive == true
                         select new MenuItem {
                    Id = rw.ID,
                    Category = rw.Category,
                    Parent = rw.Parent,
                    Area = rw.Area,
                    AreaText = rw.AreaDisplayText,
                    Controller = rw.Controller,
                    ControllerText = rw.ControllerDisplayText,
                    Action = rw.Action,
                    ActionText = rw.ActionDisplayText,
                    ItemOrder = rw.ItemOrder
                }).ToList();

                categories = db.tbl_menu_category.OrderBy(x => x.MenuOrder).Select(x => new MenuCategory()
                {
                    Id           = x.Id,
                    CategoryName = x.CategoryName
                }).ToList();


                if (categories.Count > 0)
                {
                    foreach (var category in categories)
                    {
                        var categoryChildItems = items.Where(x => x.Category == category.Id).Select(x => x).ToList();

                        if (categoryChildItems.Count > 0)
                        {
                            category.ChildItems = categoryChildItems;
                        }
                    }
                }
            }

            return(categories);
        }
Пример #2
0
        public static List <SelectListItem> LoadRoles()
        {
            IdentityManager im    = new IdentityManager();
            var             items = im.GetAllRoles();

            List <SelectListItem> selectItems = new List <SelectListItem>();

            foreach (var item in items)
            {
                selectItems.Add(new SelectListItem()
                {
                    Value = item.Name,
                    Text  = item.Name
                });
            }
            return(selectItems);
        }
Пример #3
0
        public List <string> GetUsersRole(string userId)
        {
            if (String.IsNullOrWhiteSpace(userId))
            {
                return(new List <string>());
            }

            IdentityManager im       = new IdentityManager();
            string          userName = im.GetUserNameById(userId);

            if (String.IsNullOrWhiteSpace(userName))
            {
                return(new List <string>());
            }

            return(um.GetRoles(userId).ToList <string>());
        }
Пример #4
0
        public List <SelectListItem> AllRolesToSelectListItem()
        {
            List <SelectListItem> roleItems = new List <SelectListItem>();
            IdentityManager       im        = new IdentityManager();
            List <IdentityRole>   roles     = im.GetAllRoles();

            foreach (var role in roles)
            {
                SelectListItem newItem = new SelectListItem();
                newItem.Value    = role.Id;
                newItem.Text     = role.Name;
                newItem.Selected = false;

                roleItems.Add(newItem);
            }

            return(roleItems);
        }