/// <summary> /// Thêm mới danh sách quyền từ hệ thống /// </summary> /// <param name="request"></param> /// <returns></returns> public ActionResult GetController([DataSourceRequest] DataSourceRequest request) { string namespaces = "LinJas.Areas.AdminLinja.Controllers"; // đọc các controller và action Assembly asm = Assembly.GetExecutingAssembly(); var controllerActionList = asm.GetTypes() .Where(type => typeof(System.Web.Mvc.Controller).IsAssignableFrom(type) && type.Namespace.Contains(namespaces)) .SelectMany(type => type.GetMethods(BindingFlags.Instance | BindingFlags.DeclaredOnly | BindingFlags.Public)) .Where(m => !m.GetCustomAttributes(typeof(System.Runtime.CompilerServices.CompilerGeneratedAttribute), true).Any()) .Select(x => new ControllerViewModel { Controller = x.DeclaringType.Name.Replace("Controller", ""), Action = x.Name, Attributes = string.Join(",", x.GetCustomAttributes().Select(a => a.GetType().Name.Replace("Attribute", ""))) }) .OrderBy(x => x.Controller).ThenBy(x => x.Action).ToList(); //Thêm mới vào db var result = 0; var text = "Thêm thành công"; foreach (var item in controllerActionList) { AspController flag = _db.AspControllers.Find(item.Controller, item.Action); if (flag == null) { result = _db.Database.ExecuteSqlCommand( TVConstants.StoredProcedure.AdminRole.AddController, item.Controller, item.Action, "", "", 0); if (result == 0) { text = "Thêm Thất bại"; } } } return(Json(new { Num = result, Message = text }, JsonRequestBehavior.AllowGet)); }
public static bool IsSelected(this AspController ctrl, string roleId) { using (ApplicationDbContext context = new ApplicationDbContext()) { var rolesController = context.AspRoleControllers.Find(roleId, ctrl.Controller, ctrl.Action); return(rolesController == null ? false : true); } }
public void GetAllController() { using (ApplicationDbContext context = new ApplicationDbContext()) { Assembly asm = Assembly.GetAssembly(typeof(CarDealer.MvcApplication)); var controlleractionlist = asm.GetTypes() .Where(type => typeof(System.Web.Mvc.Controller).IsAssignableFrom(type)) .SelectMany(type => type.GetMethods(BindingFlags.Instance | BindingFlags.DeclaredOnly | BindingFlags.Public)) .Where(m => !m .GetCustomAttributes(typeof(System.Runtime.CompilerServices.CompilerGeneratedAttribute), true) .Any()) .Select(x => new { Controller = x.DeclaringType.Name, Action = x.Name, ReturnType = x.ReturnType.Name, Attributes = String.Join(",", x.GetCustomAttributes().Select(a => a.GetType().Name.Replace("Attribute", ""))) }) .OrderBy(x => x.Controller).ThenBy(x => x.Action).ToList(); foreach (var item in controlleractionlist) { if (item.Controller == "AccountController" || (!item.Action.Contains("Edit") && !item.Action.Contains("Create") && !item.Action.Contains("Delete") && !item.Action.Contains("Detail")) || item.Controller == "ManageController" || item.Action == "EditDetail" || item.Action == "DetailsCar" || item.Action == "DeleteConfirmed") { continue; } AspController itemAdd = context.AspControllers.Find(item.Controller, item.Action); if (context.AspControllers.Find(item.Controller, "EditStat") == null && (item.Controller != "UsersController" && item.Controller != "RoleController")) { context.AspControllers.Add(new AspController { Action = "EditStat", Controller = item.Controller }); } if (itemAdd == null) { itemAdd = new AspController { Controller = item.Controller, Action = item.Action }; context.AspControllers.Add(itemAdd); var all = context.AspControllers.GroupBy(c => c.Controller); context.SaveChanges(); } } } }
public ActionResult GetController() { Assembly asm = Assembly.GetAssembly(typeof(CarDealer.MvcApplication)); var controlleractionlist = asm.GetTypes() .Where(type => typeof(System.Web.Mvc.Controller).IsAssignableFrom(type)) .SelectMany(type => type.GetMethods(BindingFlags.Instance | BindingFlags.DeclaredOnly | BindingFlags.Public)) .Where(m => !m.GetCustomAttributes(typeof(System.Runtime.CompilerServices.CompilerGeneratedAttribute), true).Any()) .Select(x => new { Controller = x.DeclaringType.Name, Action = x.Name, ReturnType = x.ReturnType.Name, Attributes = String.Join(",", x.GetCustomAttributes().Select(a => a.GetType().Name.Replace("Attribute", ""))) }) .OrderBy(x => x.Controller).ThenBy(x => x.Action).ToList(); foreach (var item in controlleractionlist) { if (item.Controller == "AccountController" || (!item.Action.Contains("Edit") && !item.Action.Contains("Create") && !item.Action.Contains("Delete") && !item.Action.Contains("Detail")) || item.Controller == "ManageController" || item.Action == "EditDetail" || item.Action == "DetailsCar") { continue; } try { AspController itemAdd = context.AspControllers.Find(item.Controller, item.Action); if (itemAdd == null) { itemAdd = new AspController { Controller = item.Controller, Action = item.Action }; context.AspControllers.Add(itemAdd); context.SaveChanges(); } } catch (Exception) { throw new Exception(); } } return(View(context.AspControllers.ToList())); }