public JsonResult GetModules(string UserModeCode)
        {
            ModuleModels mod = new ModuleModels();
            DataTable    dt  = new DataTable();

            dt = mod.GetAvailableModules();
            List <ModuleObject> obj = new List <ModuleObject>();

            //loop the data table and create the module object
            foreach (DataRow dr in dt.Rows)
            {
                bool result   = ModuleModels.checkAccess(UserModeCode, Convert.ToInt32(dr["Id"].ToString()));
                bool hasChild = ModuleModels.hasChild(Convert.ToInt32(dr["Id"].ToString()));
                int  count    = ModuleModels.getChildCount(Convert.ToInt32(dr["Id"].ToString()));
                obj.Add(new ModuleObject
                {
                    Id          = Convert.ToInt32(dr["Id"].ToString()),
                    ParentId    = Convert.ToInt32(dr["ParentId"].ToString()),
                    Name        = dr["Name"].ToString(),
                    Description = dr["Description"].ToString(),
                    IsEnabled   = result,
                    HasChild    = hasChild,
                    ChildCount  = count
                });
            }

            //serialize the object to json
            string json = JsonConvert.SerializeObject(obj);

            //return the json object
            return(Json(json, JsonRequestBehavior.AllowGet));
        }
Exemplo n.º 2
0
        public List <MenuObject> GenerateMenu(int child, int parent, string usertype)
        {
            Dictionary <int, MenuObject> header = new Dictionary <int, MenuObject>();
            List <MenuObject>            res    = new List <MenuObject>();
            ModuleModels mod   = new ModuleModels();
            DataTable    dtMod = mod.GetAvailableModules();

            bool is_active = false;

            foreach (DataRow row in dtMod.Rows)
            {
                List <MenuObject> subitems = new List <MenuObject>();
                MenuObject        menuobj  = new MenuObject();

                Dictionary <string, object> details = new Dictionary <string, object>();
                is_active = false;
                if (Int32.Parse(row["ParentId"].ToString()) == 0)
                {
                    try
                    {
                        if (mod.validateParentModule(row["Id"].ToString()))
                        {
                            if (mod.validateAccess(usertype, row["Id"].ToString()))
                            {
                                if (Int32.Parse(row["Id"].ToString()) == parent || Int32.Parse(row["Id"].ToString()) == child)
                                {
                                    is_active = true;
                                }

                                menuobj.Id       = Int32.Parse(row["Id"].ToString());
                                menuobj.Name     = row["Name"].ToString();
                                menuobj.Icon     = row["Icon"].ToString();
                                menuobj.IsActive = is_active;
                                menuobj.URL      = row["URL"].ToString();

                                header.Add(Int32.Parse(row["Id"].ToString()), menuobj);

                                res.Add(menuobj);
                            }
                            else
                            {
                                if (mod.validateMenu(usertype, row["Id"].ToString()))
                                {
                                    if (Int32.Parse(row["Id"].ToString()) == parent || Int32.Parse(row["Id"].ToString()) == child)
                                    {
                                        is_active = true;
                                    }

                                    menuobj.Id       = Int32.Parse(row["Id"].ToString());
                                    menuobj.Name     = row["Name"].ToString();
                                    menuobj.Icon     = row["Icon"].ToString();
                                    menuobj.IsActive = is_active;
                                    menuobj.URL      = row["URL"].ToString();

                                    header.Add(Int32.Parse(row["Id"].ToString()), menuobj);

                                    res.Add(menuobj);
                                }
                            }
                        }
                    }
                    catch { }
                }
                else
                {
                    try
                    {
                        if (mod.validateAccess(usertype, row["Id"].ToString()))
                        {
                            if (Int32.Parse(row["Id"].ToString()) == child)
                            {
                                is_active = true;
                            }

                            menuobj.Id       = Int32.Parse(row["Id"].ToString());
                            menuobj.Name     = row["Name"].ToString();
                            menuobj.Icon     = row["Icon"].ToString();
                            menuobj.IsActive = is_active;
                            menuobj.URL      = row["URL"].ToString();

                            if (header[Int32.Parse(row["ParentId"].ToString())].Items != null)
                            {
                                subitems = header[Int32.Parse(row["ParentId"].ToString())].Items;
                            }

                            subitems.Add(menuobj);

                            header[Int32.Parse(row["ParentId"].ToString())].Items = subitems;
                        }
                    }
                    catch { }
                }
            }

            return(res);
        }
Exemplo n.º 3
0
        public List <MenuObject> PrepareMenu(int child, int parent, string usertype, int userId)
        {
            Dictionary <int, MenuObject> header = new Dictionary <int, MenuObject>();
            List <MenuObject>            res    = new List <MenuObject>();
            ModuleModels mod       = new ModuleModels();
            DataTable    dtMod     = mod.GetAvailableModules();
            DataTable    dtUserMod = mod.GetUserModules(userId);

            bool is_active = false;

            if (usertype == "superadmin")
            {
                foreach (DataRow row in dtMod.Rows)
                {
                    List <MenuObject> subitems = new List <MenuObject>();
                    MenuObject        menuobj  = new MenuObject();

                    Dictionary <string, object> details = new Dictionary <string, object>();
                    is_active = false;
                    if (Int32.Parse(row["ParentId"].ToString()) == 0)
                    {
                        if (Int32.Parse(row["Id"].ToString()) == parent || Int32.Parse(row["Id"].ToString()) == child)
                        {
                            is_active = true;
                        }

                        menuobj.Id       = Int32.Parse(row["Id"].ToString());
                        menuobj.Name     = row["Name"].ToString();
                        menuobj.Icon     = row["Icon"].ToString();
                        menuobj.IsActive = is_active;
                        menuobj.URL      = row["URL"].ToString();

                        header.Add(Int32.Parse(row["Id"].ToString()), menuobj);

                        res.Add(menuobj);
                    }
                    else
                    {
                        if (Int32.Parse(row["Id"].ToString()) == child)
                        {
                            is_active = true;
                        }

                        menuobj.Id       = Int32.Parse(row["Id"].ToString());
                        menuobj.Name     = row["Name"].ToString();
                        menuobj.Icon     = row["Icon"].ToString();
                        menuobj.IsActive = is_active;
                        menuobj.URL      = row["URL"].ToString();

                        if (header[Int32.Parse(row["ParentId"].ToString())].Items != null)
                        {
                            subitems = header[Int32.Parse(row["ParentId"].ToString())].Items;
                        }

                        subitems.Add(menuobj);

                        header[Int32.Parse(row["ParentId"].ToString())].Items = subitems;
                    }
                }
            }
            else
            {
                List <int> p = new List <int>();
                List <int> c = new List <int>();

                foreach (DataRow row in dtUserMod.Rows)
                {
                    p.Add(Int32.Parse(row["ParentId"].ToString()));
                    c.Add(Int32.Parse(row["ObjectId"].ToString()));
                }

                foreach (DataRow row in dtMod.Rows)
                {
                    List <MenuObject> subitems = new List <MenuObject>();
                    MenuObject        menuobj  = new MenuObject();

                    Dictionary <string, object> details = new Dictionary <string, object>();
                    is_active = false;
                    if (Int32.Parse(row["ParentId"].ToString()) == 0)
                    {
                        if (p.Contains(Int32.Parse(row["Id"].ToString())) || c.Contains(Int32.Parse(row["Id"].ToString())))
                        {
                            if (Int32.Parse(row["Id"].ToString()) == parent || Int32.Parse(row["Id"].ToString()) == child)
                            {
                                is_active = true;
                            }

                            menuobj.Id       = Int32.Parse(row["Id"].ToString());
                            menuobj.Name     = row["Name"].ToString();
                            menuobj.Icon     = row["Icon"].ToString();
                            menuobj.IsActive = is_active;
                            menuobj.URL      = row["URL"].ToString();

                            header.Add(Int32.Parse(row["Id"].ToString()), menuobj);

                            res.Add(menuobj);
                        }
                    }
                    else
                    {
                        if (c.Contains(Int32.Parse(row["Id"].ToString())))
                        {
                            if (Int32.Parse(row["Id"].ToString()) == child)
                            {
                                is_active = true;
                            }

                            menuobj.Id       = Int32.Parse(row["Id"].ToString());
                            menuobj.Name     = row["Name"].ToString();
                            menuobj.Icon     = row["Icon"].ToString();
                            menuobj.IsActive = is_active;
                            menuobj.URL      = row["URL"].ToString();

                            if (header[Int32.Parse(row["ParentId"].ToString())].Items != null)
                            {
                                subitems = header[Int32.Parse(row["ParentId"].ToString())].Items;
                            }

                            subitems.Add(menuobj);

                            header[Int32.Parse(row["ParentId"].ToString())].Items = subitems;
                        }
                    }
                }
            }

            return(res);
        }
Exemplo n.º 4
0
        public Dictionary <string, object> GetAvailableModules(string _id, string _parentid)
        {
            ModuleModels modules = new ModuleModels();

            Dictionary <string, object> response         = new Dictionary <string, object>();
            Dictionary <string, object> menu             = new Dictionary <string, object>();
            Dictionary <string, object> submenu_temp_arr = new Dictionary <string, object>();
            List <object> submenu_header = new List <object>();
            List <object> z             = new List <object>();
            DataTable     dTableModules = modules.GetAvailableModules();

            foreach (DataRow dataRow in dTableModules.Rows)
            {
                if (dataRow["ParentId"].ToString() == "0")
                {
                    bool   isActive = false;
                    string alvin    = dataRow["Id"].ToString();
                    if (_parentid == alvin)
                    {
                        isActive = true;
                    }
                    menu.Add(dataRow["Id"].ToString(),
                             new Dictionary <string, object> {
                        { "Id", dataRow["Id"].ToString() },
                        { "Name", dataRow["Name"].ToString() },
                        { "Icon", dataRow["Icon"].ToString() },
                        { "items", new List <object>() },
                        { "is_active", isActive },
                        { "URL", dataRow["URL"].ToString() },
                    }
                             );
                }
                else
                {
                    bool isActive = false;
                    if (_id == dataRow["Id"].ToString())
                    {
                        isActive = true;
                    }

                    Dictionary <string, object> submenu_details = new Dictionary <string, object>();
                    Dictionary <string, object> y = new Dictionary <string, object>();
                    submenu_details.Add("Id", dataRow["Id"].ToString());
                    submenu_details.Add("Name", dataRow["Name"].ToString());
                    submenu_details.Add("Icon", dataRow["Icon"].ToString());
                    submenu_details.Add("items", new Dictionary <string, object>());
                    submenu_details.Add("is_active", isActive);
                    submenu_details.Add("URL", dataRow["URL"].ToString());

                    //submenu_temp_arr.Add(dataRow["ParentId"].ToString(), submenu_details);

                    submenu_header.Add(submenu_details);
                    //menu.Add(dataRow["Id"].ToString(), new Dictionary<string, object>() {
                    //    { "items",submenu }
                    //});

                    if (menu.ContainsKey(dataRow["ParentId"].ToString()))
                    {
                        var x = menu[dataRow["ParentId"].ToString()];
                        y = x as Dictionary <string, object>;
                        z = y["items"] as List <object>;
                        z.Add(submenu_details);
                        y["items"] = z;
                    }

                    //foreach (DataColumn column in dTableModules.Columns)
                    //{
                    //    //ColumnName = column.ColumnName;
                    //    //ColumnData = dataRow[column].ToString();
                    //}
                    //Console.WriteLine("--- Row ---"); // Print separator.
                    //foreach (var item in dataRow.ItemArray) // Loop over the items.
                    //{
                    //    Console.Write("Item: "); // Print label.
                    //    Console.WriteLine(item); // Invokes ToString abstract method.
                    //}
                }
            }
            return(menu);
        }