コード例 #1
0
 public PartialViewResult AdminMenu()
 {
     try
     {
         CSF_MVCEntities entities      = new CSF_MVCEntities();
         CSF_Users_DAO   objUserDao    = new CSF_Users_DAO();
         string          username      = HttpContext.User.Identity.Name;
         int             intGuestGroup = Convert.ToInt32(System.Configuration.ConfigurationManager.AppSettings["IDGuestGroup"]);
         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 == true).OrderBy(x => x.Order).ToList();
         }
         else
         {
             listAllPage = entities.CSF_Pages.Where(x => x.IsAdmin == true && x.IsBlank == false && x.IsActive == true).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());
     }
 }
コード例 #2
0
ファイル: CheckPermission.cs プロジェクト: hunglv83/WebGIS
        public override void OnActionExecuting(ActionExecutingContext filterContext)
        {
            try
            {
                var descriptor               = filterContext.ActionDescriptor;
                var actionName               = descriptor.ActionName;
                var controllerName           = descriptor.ControllerDescriptor.ControllerName;
                DT_WebGISEntities MyContext  = new DT_WebGISEntities();
                CSF_Users_DAO     objUserDao = new CSF_Users_DAO();
                string            username   = filterContext.HttpContext.User.Identity.Name;

                if (!string.IsNullOrEmpty(username))
                {
                    int        intGuestGroup    = Convert.ToInt32(System.Configuration.ConfigurationManager.AppSettings["IDGuestGroup"]);
                    List <int> listUserRole     = objUserDao.GetRoleIDByUserName(username, intGuestGroup);
                    string     ControllerAction = controllerName + "-" + actionName;
                    var        ListPermission   = (from a in MyContext.CSF_RoleFunction
                                                   join b in MyContext.CSF_Functions on a.FunctionID equals b.ID
                                                   where listUserRole.Contains(a.RoleID)
                                                   select new { ca = b.Controller_Action.ToLower() }).ToList();
                    //write log
                    int intUserID = objUserDao.GetUserIDByUserName(username);
                    if (intUserID > 0)
                    {
                        CSF_Logs objLog = new CSF_Logs();
                        objLog.Controller_Action = controllerName + "-" + actionName;
                        objLog.CreateDate        = System.DateTime.Now;
                        objLog.UserCreate        = intUserID;
                        //objLog.Content = descriptor.ToString();
                        MyContext.CSF_Logs.Add(objLog);
                        MyContext.SaveChanges();
                    }
                    var permission = ListPermission.Where(x => x.ca.Contains(ControllerAction.ToLower())).FirstOrDefault();
                    if (permission == null && username.ToLower().Trim() != "host")
                    {
                        base.OnActionExecuting(filterContext);
                        filterContext.Result = new RedirectToRouteResult(new RouteValueDictionary {
                            { "controller", "home" }, { "action", "index" }, { "area", "" }
                        });
                    }
                }
                else
                {
                    //filterContext.Result = new RedirectToRouteResult(new RouteValueDictionary { { "controller", "home" }, { "action", "login" }, { "area", "" } });

                    filterContext.Result = new RedirectToRouteResult(new RouteValueDictionary {
                        { "Area", "" },
                        { "Controller", "home" },
                        { "Action", "login" },
                        { "RedirectUrl", filterContext.HttpContext.Request.Url }
                    }
                                                                     );
                }
            }
            catch (Exception ex)
            {
                Logs.WriteLog(ex);
            }
        }
コード例 #3
0
 public PartialViewResult MainMenu()
 {
     try
     {
         ViewBag.URLIMAGE = System.Configuration.ConfigurationManager.AppSettings["UrlImage"];
         int intGuestGroup = Convert.ToInt32(System.Configuration.ConfigurationManager.AppSettings["IDGuestGroup"]);
         CSF_MVCEntities entities = new CSF_MVCEntities();
         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();
         }
         else
         {
             listAllPage = entities.CSF_Pages.Where(x => x.IsAdmin == false && x.IsBlank == false && x.IsActive == true).OrderBy(x => x.Order).ToList();
         }
         //
         int sanphamtronggio = 0;
         if (Session["cart"] != null)
         {
             List<ShoppingCart> lCart = (List<ShoppingCart>)Session["cart"];
             sanphamtronggio = lCart.Count();
         }
         string stringMenu = buildTreeMenu(listAllPage, sanphamtronggio);
         MainMenu mainMenu = new MainMenu();
         mainMenu.stringMenu = stringMenu;
         return PartialView(mainMenu);
     }
     catch (Exception ex)
     {
         Logs.WriteLog(ex);
         return PartialView();
     }
 }