コード例 #1
0
        public PartialViewResult MainMenu()
        {
            try
            {
                int intGuestGroup              = Convert.ToInt32(System.Configuration.ConfigurationManager.AppSettings["IDGuestGroup"]);
                DT_WebGISEntities entities     = new DT_WebGISEntities();
                CSF_Users_DAO     objUserDao   = new CSF_Users_DAO();
                string            username     = HttpContext.User.Identity.Name;
                List <int>        lRoleID      = objUserDao.GetRoleIDByUserName(username, intGuestGroup);
                string            stringRoleID = String.Join(",", lRoleID);
                //
                List <CSF_Pages> listAllPage = new List <CSF_Pages>();
                if (username.Trim().ToLower() != "host")
                {
                    //var lPageActiveID = entities.CSF_Pages_GetPageByRoleID(stringRoleID).Select(x => (int)x.id).ToList();
                    //listAllPage = entities.CSF_Pages.Where(x => lPageActiveID.Contains(x.ID) && x.IsAdmin == false).OrderBy(x => x.Order).ToList();

                    var lPageActiveID = entities.CSF_Pages_GetPageByRoleID(stringRoleID).Select(x => (int)x.id).ToList();
                    listAllPage = entities.CSF_Pages
                                  .Where(x => lPageActiveID.Contains(x.ID) && x.IsAdmin == false)
                                  .Join(entities.CSF_Modules,
                                        pg => pg.ModuleID, // Primary Key
                                        md => md.ID,       // Foreign Key
                                        (pg, md) => new { CSF_Pages = pg, CSF_Modules = md })
                                  .Where(pgm => pgm.CSF_Modules.IsActive == false)
                                  .Select(pgm => pgm.CSF_Pages)
                                  .OrderBy(x => x.Order)
                                  .ToList();
                }
                else
                {
                    //listAllPage = entities.CSF_Pages.Where(x => x.IsAdmin == false && x.IsBlank == false && x.IsActive == true).OrderBy(x => x.Order).ToList();

                    listAllPage = entities.CSF_Pages
                                  .Where(x => x.IsAdmin == false && x.IsBlank == false && x.IsActive == true)
                                  .Join(entities.CSF_Modules,
                                        pg => pg.ModuleID, // Primary Key
                                        md => md.ID,       // Foreign Key
                                        (pg, md) => new { CSF_Pages = pg, CSF_Modules = md })
                                  .Where(pgm => pgm.CSF_Modules.IsActive == false)
                                  .Select(pgm => pgm.CSF_Pages)
                                  .OrderBy(x => x.Order)
                                  .ToList();
                }
                //
                string   stringMenu = buildTreeMenu(listAllPage);
                MainMenu mainMenu   = new MainMenu();
                mainMenu.stringMenu = stringMenu;
                return(PartialView(mainMenu));
            }
            catch (Exception ex)
            {
                Logs.WriteLog(ex);
                return(PartialView());
            }
        }