Esempio n. 1
0
        public ActionResult GetPermissionList()
        {
            var moduleListWithActions = new List <GroupModuleList>();

            var moduleList = new ModulesApiController().GetModules();

            foreach (var module in moduleList)
            {
                var moduleData = moduleListWithActions.Where(a => a.Grp_Code == module.Grp_Code).FirstOrDefault();
                if (moduleData != null)
                {
                    var modules = moduleData.Modules.Where(a => a.Mod_Code == module.Mod_Code).FirstOrDefault();
                    if (modules != null)
                    {
                        modules.Actions.Add(new ActionList {
                            Action = module.Action, IsSelected = false
                        });
                    }
                    else
                    {
                        modules = new ModuleList {
                            Mod_Code = module.Mod_Code, Mod_Name = module.Mod_Code, Actions = new List <ActionList>()
                            {
                                new ActionList {
                                    Action = module.Action, IsSelected = false
                                }
                            }, IsSelected = false
                        };
                        moduleData.Modules.Add(modules);
                    }
                }
                else
                {
                    moduleData          = new GroupModuleList();
                    moduleData.Grp_Code = module.Grp_Code;
                    moduleData.Grp_Desc = module.Grp_Desc;
                    moduleData.Modules  = new List <ModuleList>()
                    {
                        new ModuleList {
                            Mod_Code = module.Mod_Code, Mod_Name = module.Mod_Code, Actions = new List <ActionList>()
                            {
                                new ActionList {
                                    Action = module.Action, IsSelected = false
                                }
                            }, IsSelected = false
                        }
                    };
                    moduleListWithActions.Add(moduleData);
                }
            }
            return(Json(moduleListWithActions, JsonRequestBehavior.AllowGet));
        }
        public HttpResponseMessage GetMenu()
        {
            var moduleListWithActions = new List <MGroupModuleList>();
            //if (HttpContext.Current.Session["Code"].ToString() != null)
            //{
            //    string Code = Convert.ToString(HttpContext.Current.Session["Code"]);
            //}

            string Code1      = "A000000";
            var    moduleList = new ModulesApiController().GetMenu(Code1);

            foreach (var module in moduleList)
            {
                var moduleData = moduleListWithActions.Where(a => a.Grp_Code == module.Grp_Code).FirstOrDefault();
                if (moduleData != null)
                {
                    var modules = moduleData.Modules.Where(a => a.Mod_Code == module.Mod_Code).FirstOrDefault();
                    if (modules != null)
                    {
                        var action = new ActionList {
                            Action = module.Action, IsSelected = false
                        };
                        modules.Actions.Add(action);
                        var subModule = modules.SubModuleList.Where(a => a.SubMenu == module.SubMenu).FirstOrDefault();
                        if (subModule != null)
                        {
                            subModule.Actions.Add(action);
                        }
                        else if (module.SubMenu != null)
                        {
                            modules.SubModuleList.Add(new SubModuleList {
                                SubMenu = module.SubMenu, Actions = new List <ActionList>()
                                {
                                    action
                                }, IsSelected = false, ActionName = module.ActionName, ControllerName = module.ControllerName
                            });
                        }
                    }
                    else
                    {
                        var subModuleList = module.SubMenu != null ? new List <SubModuleList>()
                        {
                            new SubModuleList {
                                SubMenu = module.SubMenu, Actions = new List <ActionList>()
                                {
                                    new ActionList {
                                        Action = module.Action, IsSelected = false
                                    }
                                }, IsSelected = false, ActionName = module.ActionName, ControllerName = module.ControllerName
                            }
                        } : new List <SubModuleList>();
                        modules = new MenuModuleList {
                            Mod_Code = module.Mod_Code, Menu_Desc = module.Menu_Desc, Mod_Name = module.Mod_Code, ControllerName = module.ControllerName, ActionName = module.ActionName, SubModuleList = subModuleList, Actions = new List <ActionList>()
                            {
                                new ActionList {
                                    Action = module.Action, IsSelected = false
                                }
                            }, IsSelected = false
                        };
                        moduleData.Modules.Add(modules);
                    }
                }
                else
                {
                    moduleData          = new MGroupModuleList();
                    moduleData.Grp_Code = module.Grp_Code;
                    moduleData.Grp_Desc = module.Grp_Desc;
                    if (module.Mod_Code == module.Grp_Code)
                    {
                        moduleData.treeview = "treeview"; moduleData.treeviewmenu = "treeview-menu";
                    }
                    if (module.Active == true)
                    {
                        moduleData.arrow = "fa fa-angle-left pull-right"; moduleData.hrefurl = "#";
                    }
                    else
                    {
                        moduleData.arrow = ""; moduleData.hrefurl = "../Account/Home";
                    }


                    var subModuleList = module.SubMenu != null ? new List <SubModuleList>()
                    {
                        new SubModuleList {
                            SubMenu = module.SubMenu, Actions = new List <ActionList>()
                            {
                                new ActionList {
                                    Action = module.Action, IsSelected = false
                                }
                            }, IsSelected = false, ActionName = module.ActionName, ControllerName = module.ControllerName
                        }
                    } : new List <SubModuleList>();

                    moduleData.Modules = new List <MenuModuleList>()
                    {
                        new MenuModuleList {
                            Mod_Code = module.Mod_Code, Menu_Desc = module.Menu_Desc, Mod_Name = module.Mod_Code, ControllerName = module.ControllerName, ActionName = module.ActionName, SubModuleList = subModuleList, Actions = new List <ActionList>()
                            {
                                new ActionList {
                                    Action = module.Action, IsSelected = false
                                }
                            }, IsSelected = false
                        }
                    };
                    moduleListWithActions.Add(moduleData);
                }
            }
            return(Request.CreateResponse(HttpStatusCode.OK, moduleListWithActions));
        }
Esempio n. 3
0
        public JsonResult GetMenu()
        {
            var    moduleListWithActions = new List <MGroupModuleList>();
            string Code = Convert.ToString(Session["Code"]);

            Code = "A000000";
            var moduleList = new ModulesApiController().GetMenu(Code);

            foreach (var module in moduleList)
            {
                var moduleData = moduleListWithActions.Where(a => a.Grp_Code == module.Grp_Code).FirstOrDefault();
                if (moduleData != null)
                {
                    var modules = moduleData.Modules.Where(a => a.Mod_Code == module.Mod_Code).FirstOrDefault();
                    if (modules != null)
                    {
                        var action = new ActionList {
                            Action = module.Action, IsSelected = false
                        };
                        modules.Actions.Add(action);
                        var subModule = modules.SubModuleList.Where(a => a.SubMenu == module.SubMenu).FirstOrDefault();
                        if (subModule != null)
                        {
                            subModule.Actions.Add(action);
                        }
                        else if (module.SubMenu != null)
                        {
                            modules.SubModuleList.Add(new SubModuleList {
                                SubMenu = module.SubMenu, Actions = new List <ActionList>()
                                {
                                    action
                                }, IsSelected = false, ActionName = module.ActionName, ControllerName = module.ControllerName
                            });
                        }
                    }
                    else
                    {
                        var subModuleList = module.SubMenu != null ? new List <SubModuleList>()
                        {
                            new SubModuleList {
                                SubMenu = module.SubMenu, Actions = new List <ActionList>()
                                {
                                    new ActionList {
                                        Action = module.Action, IsSelected = false
                                    }
                                }, IsSelected = false, ActionName = module.ActionName, ControllerName = module.ControllerName
                            }
                        } : new List <SubModuleList>();
                        modules = new MenuModuleList {
                            Mod_Code = module.Mod_Code, Menu_Desc = module.Menu_Desc, Mod_Name = module.Mod_Code, ControllerName = module.ControllerName, ActionName = module.ActionName, SubModuleList = subModuleList, Actions = new List <ActionList>()
                            {
                                new ActionList {
                                    Action = module.Action, IsSelected = false
                                }
                            }, IsSelected = false
                        };
                        moduleData.Modules.Add(modules);
                    }
                }
                else
                {
                    moduleData          = new MGroupModuleList();
                    moduleData.Grp_Code = module.Grp_Code;
                    moduleData.Grp_Desc = module.Grp_Desc;
                    if (module.Mod_Code == module.Grp_Code)
                    {
                        moduleData.treeview = "treeview"; moduleData.treeviewmenu = "treeview-menu";
                    }
                    if (module.Active == true)
                    {
                        moduleData.arrow = "fa fa-angle-left pull-right"; moduleData.hrefurl = "#";
                    }
                    else
                    {
                        moduleData.arrow = ""; moduleData.hrefurl = "../Account/Home";
                    }


                    var subModuleList = module.SubMenu != null ? new List <SubModuleList>()
                    {
                        new SubModuleList {
                            SubMenu = module.SubMenu, Actions = new List <ActionList>()
                            {
                                new ActionList {
                                    Action = module.Action, IsSelected = false
                                }
                            }, IsSelected = false, ActionName = module.ActionName, ControllerName = module.ControllerName
                        }
                    } : new List <SubModuleList>();

                    moduleData.Modules = new List <MenuModuleList>()
                    {
                        new MenuModuleList {
                            Mod_Code = module.Mod_Code, Menu_Desc = module.Menu_Desc, Mod_Name = module.Mod_Code, ControllerName = module.ControllerName, ActionName = module.ActionName, SubModuleList = subModuleList, Actions = new List <ActionList>()
                            {
                                new ActionList {
                                    Action = module.Action, IsSelected = false
                                }
                            }, IsSelected = false
                        }
                    };
                    moduleListWithActions.Add(moduleData);
                }
            }
            //return Json(JsonConvert.SerializeObject(moduleListWithActions), JsonRequestBehavior.AllowGet);
            return(Json(moduleListWithActions, JsonRequestBehavior.AllowGet));
        }