public ActionResult Index(RolePermisionModel model) { if (model.PostedFunction != null && model.PostedFunction.FunctionID != null) { model.AllBranch = BranchRepository.GetAll(); model.AllRole = RoleRepository.GetAll(); var rootFuncs = FunctionRepository.GetChild(0); var lstFunctions = new List<FunctionInfo>(); foreach (FunctionInfo func in rootFuncs) { lstFunctions.Add(func); LoadChildFunctions(lstFunctions, func); } model.AllFunction = lstFunctions; var deleteFunctions = model.PostedFunction.FunctionID.Where(p => !model.PostedFunction.FunctionID.Any(p2 => p2 == p)); int curUserId = UserRepository.GetCurrentUserInfo().UserID; foreach (int roleId in model.PostedRole.Id) { foreach (int branchId in model.PostedBranch.Id) { RolePermisionRepository.Clear(roleId, branchId); foreach (int functionId in model.PostedFunction.FunctionID) { RolePermisionRepository.Create(roleId, branchId, functionId, curUserId); } } } } return View(model); }
public ActionResult Index() { //ViewBag.Roles = RoleRepository.GetAll(); var model = new RolePermisionModel() { AllBranch = BranchRepository.GetAll(), AllRole = RoleRepository.GetAll(), SelectedBranch = new Collection<BranchInfo>(), SelectedRole = new Collection<RoleInfo>(), PostedBranch = new PostedBranch(), PostedRole = new PostedRole(), PostedFunction = new PostedFunction() }; var rootFuncs = FunctionRepository.GetChild(0); var lstFunctions = new List<FunctionInfo>(); foreach (FunctionInfo func in rootFuncs) { func.SetLevel(0); lstFunctions.Add(func); LoadChildFunctions(lstFunctions, func); } model.AllFunction = lstFunctions; return View(model); }