Пример #1
0
        // GET: Power
        public ActionResult Index()
        {
            List <PagePowersViewModel> ppvmList = new List <PagePowersViewModel>();

            foreach (uPages uPage in db.uPages.ToList())
            {
                PagePowersViewModel ppvmItem = new PagePowersViewModel
                {
                    uPages  = uPage,
                    uPowers = db.uPowers.Where(n => n.pageID == uPage.pageID).ToList()
                };
                ppvmList.Add(ppvmItem);
            }

            List <RolesViewModel> rvmList = new List <RolesViewModel>();

            foreach (uRoles uRole in db.uRoles.ToList())
            {
                RolesViewModel rvmItem = new RolesViewModel {
                    uRoles      = uRole,
                    uRolePowers = db.uRolePowers.Where(n => n.uRoleID == uRole.uRoleID).ToList(),
                    uRoleUsers  = db.uRoleUsers.Where(n => n.uRoleID == uRole.uRoleID).ToList()
                };
                rvmList.Add(rvmItem);
            }


            IEnumerable <uRoles>  urs   = db.uRoles.ToList();
            List <SelectListItem> ursli = new List <SelectListItem>();

            foreach (uRoles ur in urs)
            {
                ursli.Add(new SelectListItem {
                    Value = ur.uRoleID.ToString(), Text = ur.uRoleName
                });
            }

            PowerViewModel powerViewModel = new PowerViewModel
            {
                department          = db.Department.ToList(),
                pagePowersViewModel = ppvmList,
                rolesViewModel      = rvmList,
                roles = ursli
            };

            return(View(powerViewModel));
        }
Пример #2
0
        public PartialViewResult ViewRoleLevel()
        {
            List <RoleLevelViewModel> rlvms  = new List <RoleLevelViewModel>();
            IEnumerable <uRoles>      uRoles = db.uRoles.ToList();

            foreach (uRoles urole in uRoles)
            {
                List <RolesUserNames>    runasli = new List <RolesUserNames>();
                IEnumerable <uRoleUsers> urus    = db.uRoleUsers.Where(n => n.uRoleID == urole.uRoleID).ToList();
                foreach (var uru in urus)
                {
                    string         una  = db.AspNetUsers.Where(n => n.UserName == uru.uUserID).Select(n => n.Name).FirstOrDefault();
                    RolesUserNames runa = new RolesUserNames {
                        uRoleUser = uru,
                        UserName  = una
                    };
                    runasli.Add(runa);
                }

                RoleLevelViewModel rlvm = new RoleLevelViewModel {
                    uRoles         = urole,
                    uRolePowers    = db.uRolePowers.Where(n => n.uRoleID == urole.uRoleID).ToList(),
                    rolesUserNames = runasli
                };
                rlvms.Add(rlvm);
            }

            List <PagePowersViewModel> ppvmList = new List <PagePowersViewModel>();

            foreach (uPages uPage in db.uPages.ToList())
            {
                PagePowersViewModel ppvmItem = new PagePowersViewModel
                {
                    uPages  = uPage,
                    uPowers = db.uPowers.Where(n => n.pageID == uPage.pageID).ToList()
                };
                ppvmList.Add(ppvmItem);
            }

            RoleLevelWithPowerViewModel rlwpvm = new RoleLevelWithPowerViewModel {
                roleLevelViewModel  = rlvms,
                pagePowersViewModel = ppvmList
            };

            return(PartialView(rlwpvm));
        }