private async void LoadUserFeature(int IDPermission) { lstUserFeatures = await clsUserRole.Instance.SearchUserFeature(IDPermission); await RunMethodAsync(() => { trlFeature.CellValueChanging -= trlFeature_CellValueChanging; ResetCheckedNodes(); foreach (xUserFeature usr in lstUserFeatures) { TreeListNode node = trlFeature.FindNodeByKeyID(usr.IDFeature); if (node != null) { node.Checked = usr.IsEnable; xFeature feature = (xFeature)trlFeature.GetDataRecordByNode(node); feature.IsAdd = usr.IsAdd; feature.IsEdit = usr.IsEdit; feature.IsDelete = usr.IsDelete; feature.IsSave = usr.IsSave; feature.IsPrintPreview = usr.IsPrintPreview; feature.IsExportExcel = usr.IsExportExcel; } } trlFeature.CellValueChanging += trlFeature_CellValueChanging; }); }
public async Task <IActionResult> GetController() { List <xFeature> lstFeatures = new List <xFeature>(); Assembly asm = Assembly.GetExecutingAssembly(); var Controllers = asm.GetExportedTypes() .Where(x => typeof(ControllerBase).IsAssignableFrom(x) && !x.Name.Equals(typeof(BaseController <>).Name)) .Select(x => new { Controller = x.Name, Methods = x.GetMethods().Where(y => y.DeclaringType.IsSubclassOf(typeof(ControllerBase)) && y.IsPublic && !y.IsStatic).ToList() }) .Select(x => new { Controller = x.Controller.ToLower().Replace("controller", string.Empty), Actions = x.Methods.Select(y => new { Action = y.Name.ToLower(), Attributes = y.GetCustomAttributes(true).ToList() }) }); DateTime time = DateTime.Now; foreach (var controller in Controllers) { List <xFeature> lstTemps = new List <xFeature>(); foreach (var action in controller.Actions) { xFeature f = new xFeature(); HttpGetAttribute attr_Get = (HttpGetAttribute)action.Attributes.FirstOrDefault(x => x.GetType() == typeof(HttpGetAttribute)); if (attr_Get != null) { f.Method = HttpMethods.Get.ToLower(); f.Template = string.IsNullOrWhiteSpace(attr_Get.Template) ? string.Empty : attr_Get.Template.ToLower(); lstTemps.Add(f); } HttpPostAttribute attr_Post = (HttpPostAttribute)action.Attributes.FirstOrDefault(x => x.GetType() == typeof(HttpPostAttribute)); if (attr_Post != null) { f.Method = HttpMethods.Post.ToLower(); f.Template = string.IsNullOrWhiteSpace(attr_Post.Template) ? string.Empty : attr_Post.Template.ToLower(); lstTemps.Add(f); } HttpPutAttribute attr_Put = (HttpPutAttribute)action.Attributes.FirstOrDefault(x => x.GetType() == typeof(HttpPutAttribute)); if (attr_Put != null) { f.Method = HttpMethods.Put.ToLower(); f.Template = string.IsNullOrWhiteSpace(attr_Put.Template) ? string.Empty : attr_Put.Template.ToLower(); lstTemps.Add(f); } HttpDeleteAttribute attr_Delete = (HttpDeleteAttribute)action.Attributes.FirstOrDefault(x => x.GetType() == typeof(HttpDeleteAttribute)); if (attr_Delete != null) { f.Method = HttpMethods.Delete.ToLower(); f.Template = string.IsNullOrWhiteSpace(attr_Delete.Template) ? string.Empty : attr_Delete.Template.ToLower(); lstTemps.Add(f); } RouteAttribute attr_Route = (RouteAttribute)action.Attributes.FirstOrDefault(x => x.GetType() == typeof(RouteAttribute)); if (attr_Route != null) { f.Method = string.IsNullOrWhiteSpace(f.Method) ? HttpMethods.Get.ToLower() : f.Method; f.Template = string.IsNullOrWhiteSpace(attr_Route.Template) ? string.Empty : attr_Route.Template.ToLower(); lstTemps.Add(f); } f.KeyID = 0; f.NgayTao = time; f.Controller = controller.Controller; f.Action = action.Action; f.Path = string.Join('/', "api", f.Controller, f.Template).TrimEnd('/'); } lstFeatures.AddRange(lstTemps); } return(await SaveData(lstFeatures.ToArray())); }