// GET: Admin/UserBusinesses public ActionResult UpdateBusiness() { ReflectionController recontroller = new ReflectionController(); List <Type> listControllerType = recontroller.GetControllers("DesignWeb_Project.Areas.Admin.Controllers"); List <string> listcontrollerOld = db.UserBusiness.Select(k => k.BusinessID).ToList(); List <string> listPermissionOld = db.UserPermission.Select(k => k.PermissionName).ToList(); foreach (var item in listControllerType) { if (!listcontrollerOld.Contains(item.Name)) { UserBusiness ub = new UserBusiness() { BusinessID = item.Name, BusinessName = "No Description" }; db.UserBusiness.Add(ub); } List <string> listPermission = recontroller.GetActions(item); foreach (var per in listPermission) { if (!listPermissionOld.Contains(item.Name + "-" + per)) { UserPermission up = new UserPermission() { PermissionName = item.Name + "-" + per, PermissionDescription = "No Description", BusinessID = item.Name }; db.UserPermission.Add(up); } } } db.SaveChanges(); TempData["alert"] = "<div class='alert alert-success'>Đã Cập Nhật Thành Công</ div > "; return(RedirectToAction("Index")); }
// GET: Admin/Roles/Create public ActionResult Create() { List <String> roles = new List <string>(); List <Type> controllers = ReflectionController.GetControllers("WatchShop.Areas.Admin"); int numberOfControllers = controllers.Count; for (int i = 0; i < numberOfControllers; i++) { Type controller = controllers[i]; if (controller.Name != "StateController") { List <string> actions = ReflectionController.GetActions(controller); int numberOfActions = actions.Count; for (int j = 0; j < numberOfActions; j++) { string role = controller.Name.Substring(0, controller.Name.Length - 10) + "-" + actions[j]; if (!RoleDAO.Instance.IsRoleExisted(role)) { roles.Add(role); } } } } if (roles.Count == 0) { return(RedirectToAction("NoRoleLeft", "State")); } ViewBag.Roles = roles; return(View()); }
// Update danh sach nghiep vu public ActionResult UpdateBusinesses(string name) { List <Type> lstControllerTyper = ReflectionController.GetControllers("AppEnglishTest.Areas.adminstrator"); List <string> lstOldController = db.Businesses.Select(x => x.BusinessId).ToList(); List <string> lstOldPermission = db.Permissions.Select(x => x.PermissionName).ToList(); foreach (var con in lstControllerTyper) { if (!lstOldController.Contains(con.Name)) { Business bs = new Business() { BusinessId = con.Name, BusinessName = "Chua co mo ta" }; db.Businesses.Add(bs); } List <string> lstPermisses = ReflectionController.GetActions(con); foreach (var p in lstPermisses) { if (!lstOldPermission.Contains(con.Name + "-" + p)) { Permission per = new Permission() { PermissionName = con.Name + "-" + p, BusinessId = con.Name, Description = "Chưa có mô tả về chức năng này" }; db.Permissions.Add(per); } } } db.SaveChanges(); ViewBag.Error = "Update thành công"; return(RedirectToAction("Index")); }
public ActionResult UpdateBusiness() { ReflectionController rc = new ReflectionController(); List <Type> listControllerType = rc.GetControllers("ManagementDispatch.Controllers"); List <string> listControllerOld = _data.BlogBusinesses.Select(c => c.BusinessId).ToList(); List <string> listPermessionOld = _data.BlogPermissions.Select(c => c.PermissionName).ToList(); foreach (var c in listControllerType) { if (!listControllerOld.Contains(c.Name)) { BlogBusiness b = new BlogBusiness() { BusinessId = c.Name, BusinessName = "Chưa có mô tả" }; _data.BlogBusinesses.InsertOnSubmit(b); _data.SubmitChanges(); } List <string> listPermission = rc.GetActions(c); foreach (var p in listPermission) { if (!listPermessionOld.Contains(c.Name + "-" + p)) { BlogPermission permission = new BlogPermission() { PermissionName = c.Name + "-" + p, Description = "Chưa có mô tả", BusinessId = c.Name }; _data.BlogPermissions.InsertOnSubmit(permission); _data.SubmitChanges(); } } } return(RedirectToAction("ListRole")); }
public ActionResult UpdateNghiepVu() { ReflectionController rc = new ReflectionController(); List <Type> listControllerType = rc.GetControllers("QuanLyXe.Areas.Admin.Controllers"); List <string> listControllerOld = db.NghiepVus.Select(c => c.MaNghiepVu).ToList(); List <string> listPermistionOld = db.BlogPermissions.Select(p => p.PermisstionName).ToList(); foreach (var c in listControllerType) { if (!listControllerOld.Contains(c.Name)) { NghiepVu nv = new NghiepVu() { MaNghiepVu = c.Name, TenNghiepVu = "Chưa có mô tả" }; db.NghiepVus.Add(nv); } List <string> listPermisstion = rc.GetActions(c); foreach (var p in listPermisstion) { if (!listPermistionOld.Contains(c.Name + "-" + p)) { BlogPermission permission = new BlogPermission() { PermisstionName = c.Name + "-" + p, Description = "Chưa có mô tả", MaNghiepVu = c.Name }; db.BlogPermissions.Add(permission); } } } db.SaveChanges(); TempData["err"] = "<div class='alert alert-info' role='alert'><span class='glyphicon glyphicon-exclamation-sign' aria-hidden='true'></span><span class='sr-only'></span>Cập Nhật</div>"; return(RedirectToAction("Index")); }
public ActionResult SyncBusiness() { ReflectionController rc = new ReflectionController(); List <Type> listControllerType = rc.GetControllers("ShoesProject.Areas.Admin.Controllers"); List <string> listCurrentController = db.Businesses.Select(c => c.BusinessId).ToList(); List <string> listCurrentPermisson = db.Permissons.Select(p => p.PermissonName).ToList(); foreach (var c in listControllerType) { if (!listCurrentController.Contains(c.Name)) { Debug.WriteLine(c.Name); Business b = new Business { BusinessId = c.Name, BusinessName = "No Description" }; db.Businesses.Add(b); } List <String> listPermisson = rc.GetActions(c); foreach (var p in listPermisson) { if (!listCurrentPermisson.Contains(c.Name + "-" + p)) { Permisson permisson = new Permisson(); permisson.PermissonName = c.Name + "-" + p; permisson.BusinessId = c.Name; db.Permissons.Add(permisson); } } } db.SaveChanges(); return(RedirectToAction("Index")); }
public ActionResult UpdateBusiness() { ReflectionController rc = new ReflectionController(); List <Type> listControllerType = rc.GetControllers("SaleDrink.Areas.Admin.Controllers"); List <string> listControllerOld = db.Businesseses.Select(c => c.BusinessId).ToList(); List <string> listPermistionOld = db.Permissions.Select(p => p.PermissionName).ToList(); foreach (var c in listControllerType) { if (!listControllerOld.Contains(c.Name)) { UserBusiness b = new UserBusiness() { BusinessId = c.Name, BusinessName = "Chưa có mô tả" }; db.Businesseses.Add(b); } List <string> listPermission = rc.GetActions(c); foreach (var p in listPermission) { if (!listPermistionOld.Contains(c.Name + "-" + p)) { UserPermission permission = new UserPermission() { PermissionName = c.Name + "-" + p, Description = "Chưa có mô tả", BusinessId = c.Name }; db.Permissions.Add(permission); } } } db.SaveChanges(); TempData["err"] = "<div class='alert alert-info' role='alert'><span class='glyphicon glyphicon-exclamation-sign' aria-hidden='true'></span><span class='sr-only'></span> Cập nhật thành công</div>"; return(RedirectToAction("Index")); }
//lấy tất cả các controler và action insert vào db public bool UpdateBusiess(string namespances) { try { ReflectionController re = new ReflectionController(); List <Type> listControllerType = re.GetController(namespances); //truyen vào namepaces mà bạn muốn lấy controller //chứa controller List <string> listControllerOld = db.Businesses.Select(p => p.ID).ToList(); //lấy ra danh sách tên controller trong bảng //chứa action List <string> listPermisstionOld = db.Permissions.Select(p => p.PermissionName).ToList(); //lấy ra danh sach tên trong bảng foreach (var c in listControllerType) { //gáng giá trị các controller đang được lấy của namespaces cho lớp if (!listControllerOld.Contains(c.Name)) { Business business = new Business() { ID = c.Name, Name = "Chưa có mô tả" }; //thêm vào bẳng db.Businesses.Add(business); } List <string> listPermission = re.GetActions(c);//lấy danh sách các action trong controller namespaces truyền vào foreach (var p in listPermission) { if (!listPermisstionOld.Contains(c.Name + '-' + p))//kiểm tra nếu trong db chưa có thì mới thêm vào { Permission permission = new Permission() { PermissionName = c.Name + "-" + p, Desciption = "Chưa có mô tả", BusinessID = c.Name }; db.Permissions.Add(permission); } } } db.SaveChanges(); return(true); } catch (Exception) { return(false); throw; } }
// GET: administration/Home public ActionResult Index() { List <Type> lstControlller = ReflectionController.GetControllers("DemoPhanQuyen.Areas.administration.Controllers"); string htmlLstAction = "<ul>"; foreach (Type x in lstControlller) { htmlLstAction += "<li><lable><input type='checkbox' id='All_" + x.Name + "' value='" + x.Name + "' /> " + x.Name + "<lable><ul>"; foreach (string y in ReflectionController.GetActions(x)) { htmlLstAction += "<li><lable><input type='checkbox' class='" + x.Name + "' value='" + y + "' />" + y + "</lable></li>"; } htmlLstAction += "</ul></li>"; } htmlLstAction += "</ul>"; ViewBag.menu = htmlLstAction; return(View()); }
public JsonResult CapNhatDanhSachNghiepVu() { ReflectionController rc = new ReflectionController(); List <Type> listControllerType = rc.GetControllers("ResWebsite.UI.Areas.Admin"); List <string> listControllerOld = bll.LayTatCa().Select(c => c.MaNghiepVu).ToList(); List <string> listPermissionOld = quyenHanBll.LayTatCa().Select(p => p.TenQuyenHan).ToList(); foreach (var c in listControllerType) { if (!listControllerOld.Contains(c.Name)) { NghiepVu nv = new NghiepVu() { MaNghiepVu = c.Name, TenNghiepVu = "Chưa có mô tả", GhiChu = "Chưa có ghi chú", }; bll.ThemMoi(nv); } List <string> listPermisson = rc.GetActions(c); ScriptFunctionsDataContext function = new ScriptFunctionsDataContext(); foreach (var p in listPermisson) { if (!listPermissionOld.Contains(c.Name + "-" + p)) { QuyenHan quyenHan = new QuyenHan { MaQuyenHan = function.auto_maQH(), TenQuyenHan = c.Name + "-" + p, MoTa = "Chưa có mô tả", MaNghiepVu = c.Name }; quyenHanBll.ThemMoi(quyenHan); } } } return(Json( new { status = true }, JsonRequestBehavior.AllowGet)); }
public OperationResult GetAllBusiness() { try { ReflectionController reflectionController = new ReflectionController(); List <Type> listControllerType = reflectionController.GetController("ERPSystem.Areas"); List <string> listControllerOld = unitOfWork.GrantPermissionAdmin.BusinessRepository.GetAll().Select(c => c.BusinessId).ToList(); List <string> listPermissionOld = unitOfWork.GrantPermissionAdmin.PermissionRepository.GetAll().Select(x => x.PermissionName).ToList(); foreach (var c in listControllerType) { if (!listControllerOld.Contains(c.Name)) { Business b = new Business() { BusinessId = c.Name, BusinessName = "Chưa có mô tả", ModifiedDate = DateTime.Now }; unitOfWork.GrantPermissionAdmin.BusinessRepository.Add(b); } List <string> listPermission = reflectionController.GetActions(c); foreach (var p in listPermission) { if (!listPermissionOld.Contains(c.Name + "-" + p)) { Permission permission = new Permission { PermissionName = c.Name + "-" + p, Description = "Chưa có mô tả này", BusinessId = c.Name, DateModified = DateTime.Now }; unitOfWork.GrantPermissionAdmin.PermissionRepository.Add(permission); } } } unitOfWork.Complete(); operationResult.Success = true; operationResult.Message = "Đã cập nhật thành công!"; } catch (Exception ex) { operationResult.Success = false; operationResult.Message = "Lỗi " + ex.ToString(); } return(operationResult); }
public ActionResult Index() { ReflectionController refl = new ReflectionController(); List <Type> ctrls = refl.GetControllers("WebAppMobile.Controllers"); string rs = "<ul>"; foreach (Type item in ctrls) { rs += "<li>" + item.Name; List <string> lsAction = refl.GetActions(item); rs += "<ul>"; foreach (string ac in lsAction) { rs += "<li>" + ac + "</li>"; } rs += "</ul></li>"; } rs += "<ul>"; ViewBag.Ctrl = rs; return(View()); }
public ActionResult UpdateBussiness() { ReflectionController rc = new ReflectionController(); List <Type> lstType = rc.GetControllers("ShopOnlineApp.Areas.Admin"); List <string> lstControllerOld = _context.Businesss.Select(x => x.Id).ToList(); List <BusinessAction> businessActions = new List <BusinessAction>(); foreach (var item in lstType) { if (!lstControllerOld.Contains(item.Name)) { _context.Businesss.Add(new Business() { Id = item.Name, Name = "Chưa có mô tả" }); } List <string> listPermissions = rc.GetActions(item); foreach (var it in listPermissions) { if (businessActions.All(s => s.Name != item.Name + "-" + it)) { businessActions.Add(new BusinessAction { Name = item.Name + "-" + it, Description = "Chưa có mô tả", BusinessId = item.Name }); } } } _context.BusinessActions.AddRange(businessActions); _context.SaveChanges(); return(Redirect("/Admin/Business/Index")); }
//Updates Controller and Action public ActionResult UpdateBusiness(string nameSpace, string returnUrl = "Index") { //LAy danh sach Contorller va Action ReflectionController rc = new ReflectionController(); List <Type> listControllerType = rc.GetControllers("TeduCoreApp.Areas.Admin.Controllers"); List <string> listControllerOld = _context.ListControllers.Select(c => c.ControllerName).ToList(); List <string> listActionOld = _context.ListActions.Select(p => p.ActionName).ToList(); foreach (var c in listControllerType) { if (!listControllerOld.Contains(c.Name)) { ListController b = new ListController() { ControllerName = c.Name, DiscriptionAction = "Chưa có mô tả" }; _context.ListControllers.Add(b); _context.SaveChanges(); } List <string> listAction = rc.GetActions(c); foreach (var p in listAction) { if (!listActionOld.Contains(c.Name + "-" + p)) { var controllerOld = _context.ListControllers.SingleOrDefault(x => x.ControllerName == c.Name); ListAction action = new ListAction() { IdController = controllerOld.Id, ActionName = c.Name + "-" + p, Discription = "Chưa có mô tả" }; _context.ListActions.Add(action); } } } _context.SaveChanges(); TempData["err"] = "<div class='alert alert-info' role='alert'><span class='glyphicon glyphicon-exclamation-sign' aria-hidden='true'></span><span class='sr-only'></span>Cập Nhật thành công</div>"; return(RedirectToAction(returnUrl)); }
public ActionResult Capnhat_Nghiepvu() { ReflectionController rc = new ReflectionController(); List <Type> danhsach_loainghiepvu = rc.GetControllers("ERP.Web.Areas.HopLong.Controllers"); List <String> danhsach_nghiepvucu = db.CN_NGHIEP_VU.Select(c => c.ID).ToList(); List <String> danhsach_chitietnghiepvucu = db.CN_CHI_TIET_NGHIEP_VU.Select(p => p.TEN_CHI_TIET).ToList(); foreach (var c in danhsach_loainghiepvu) { if (!danhsach_nghiepvucu.Contains(c.Name)) { CN_NGHIEP_VU c_info = new CN_NGHIEP_VU() { ID = c.Name, TEN_NGHIEP_VU = c.Name, TRUC_THUOC = Session["MA_CONG_TY"].ToString() }; db.CN_NGHIEP_VU.Add(c_info); } List <String> danhsach_chitietnghiepvu = rc.GetActions(c); foreach (var p in danhsach_chitietnghiepvu) { if (!danhsach_chitietnghiepvucu.Contains(c.Name + "-" + p)) { CN_CHI_TIET_NGHIEP_VU permission = new CN_CHI_TIET_NGHIEP_VU() { TEN_CHI_TIET = c.Name + "-" + p, ID_NGHIEP_VU = c.Name, MO_TA = c.Name + "-" + p }; db.CN_CHI_TIET_NGHIEP_VU.Add(permission); } } } db.SaveChanges(); TempData["err"] = "<div class='alert alert-info' role='alert'><span class='glyphicon glyphicon-exclamation-sign' aria-hidden='true'></span><span class='sr-only'></span>Cập nhật thành công </div> "; return(RedirectToAction("Index")); }
public ActionResult Update_Controller_Info() { ReflectionController rc = new ReflectionController(); List <Type> listControllerType = rc.GetControllers("SYSTEM_MANAGEMENT.Controllers"); List <String> listControllerOld = db.LIST_CONTROLLERS.Select(c => c.CONTROLLER_ID).ToList(); List <String> listPermissionOld = db.LIST_PERMISSIONS.Select(p => p.PERMISSION_NAME).ToList(); foreach (var c in listControllerType) { if (!listControllerOld.Contains(c.Name)) { LIST_CONTROLLERS c_info = new LIST_CONTROLLERS() { CONTROLLER_ID = c.Name, CONTROLLER_NAME = "Chưa có mô tả" }; db.LIST_CONTROLLERS.Add(c_info); } List <String> listPermission = rc.GetActions(c); foreach (var p in listPermission) { if (!listPermissionOld.Contains(c.Name + "-" + p)) { LIST_PERMISSIONS permission = new LIST_PERMISSIONS() { PERMISSION_NAME = c.Name + "-" + p, DESCRIPTION = "Chưa có mô tả nào", CONTROLLER_ID = c.Name }; db.LIST_PERMISSIONS.Add(permission); } } } db.SaveChanges(); TempData["err"] = "<div class='alert alert-info' role='alert'><span class='glyphicon glyphicon-exclamation-sign' aria-hidden='true'></span><span class='sr-only'></span>Cập nhật thành công </div> "; return(RedirectToAction("Index")); }
//Cap nhat controller va action public static void CapNhat() { var entity = new QuanLyThueXeEntities(); try { ReflectionController rc = new ReflectionController(); List <Type> lstControllerType = rc.GetControllers("QuanLyThueXe"); foreach (var controller in lstControllerType) { LoaiController check = entity.LoaiControllers.SingleOrDefault(n => n.MaController == controller.Name); LoaiController add = new LoaiController(); if (check == null) { add.MaController = controller.Name; add.TenController = "Chưa mô tả"; entity.LoaiControllers.Add(add); //Lấy danh action bằng cách gọi hàm getaction List <string> listAction = rc.GetActions(controller); foreach (string action in listAction) { var ten = controller.Name + "-" + action; LoaiAction checkAction = entity.LoaiActions.SingleOrDefault(n => n.TenAction == ten); LoaiAction addAction = new LoaiAction(); if (checkAction == null) { addAction.TenAction = ten; addAction.Mota = "Chưa mô tả"; addAction.MaController = controller.Name; addAction.UrlAction = "/" + (controller.Name).Substring(0, controller.Name.Length - 10) + "/" + action; entity.LoaiActions.Add(addAction); } entity.SaveChanges(); } } else { List <string> listAction = rc.GetActions(controller); foreach (string action in listAction) { var ten = controller.Name + "-" + action; LoaiAction checkAction = entity.LoaiActions.SingleOrDefault(n => n.TenAction == ten); LoaiAction addAction = new LoaiAction(); if (checkAction == null) { addAction.TenAction = ten; addAction.Mota = "Chưa mô tả"; addAction.MaController = controller.Name; addAction.UrlAction = "/" + (controller.Name).Substring(0, controller.Name.Length - 10) + "/" + action; entity.LoaiActions.Add(addAction); } entity.SaveChanges(); } } } } catch (Exception ex) { entity.Dispose(); } }