// GET: Admin/Business public ActionResult UpdateBusiness() { db = new DBContext(); ReflectionController reflection = new ReflectionController(); List <Type> listController = reflection.GetControllers("Website.Areas.Admin"); List <string> listControllerOld = db.Businesses.Select(x => x.BusinessID).ToList(); List <string> listPermistionOld = db.Permissions.Select(x => x.Name).ToList(); foreach (var c in listController) { if (!listControllerOld.Contains(c.Name)) { Business b = new Business(); b.BusinessID = c.Name; b.BusinessName = "Chưa có mô tả"; db.Businesses.Add(b); } List <string> listPermistion = reflection.GetAction(c); foreach (var p in listPermistion) { if (!listPermistionOld.Contains(c.Name + "-" + p)) { Permission permistion = new Permission(); permistion.Name = c.Name + "-" + p; permistion.Description = "Chưa có mô tả"; permistion.BusinessID = c.Name; db.Permissions.Add(permistion); } } } if (db.SaveChanges() > 0) { SetAlert("Cập nhật thành công", "success"); return(RedirectToAction("Index")); } else { SetAlert("Không thành công", "danger"); } return(RedirectToAction("Index")); }