/* * @author : AC <*****@*****.**> * @date : 11/25/2016 2:30 PM * @description : get permissions per module per user * @params : userId(int) * @returns : array */ public List <int> GetUserModules(int userId) { List <int> res = new List <int>(); DataTable user_mod = modules.GetUserModules(userId); foreach (DataRow row in user_mod.Rows) { res.Add(Int32.Parse(row["ObjectId"].ToString())); } return(res); }
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.GetAvailabeModules(); 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); }