// GET: Power public ActionResult Index() { List <FunctionSimpleInfo> list = new List <FunctionSimpleInfo>(); ViewBag.Role = SqlHelp.GetRoles(); Function.GetFunction().ForEach(p => { if (p.SonFionctionId == null) { FunctionSimpleInfo info = new FunctionSimpleInfo(); info.Id = p.FunctionId; info.Name = p.Name; info.Content = p.Content; list.Add(info); } }); SonFunction.GetSonFunction().ForEach(p => { FunctionSimpleInfo info = new FunctionSimpleInfo(); info.Id = p.SonFunctionId; info.Name = p.Name; info.Content = p.Content; list.Add(info); }); return(View(list)); }
//新增 public static int insert(RoleFunctionDto model) { string fatherId = ""; using (IDbConnection conn = MySqlConnection()) { int result = 0; IDbTransaction transaction = conn.BeginTransaction(); try { if (!model.RoleId.IsNullOrEmpty()) { delete(model.RoleId); if (!string.IsNullOrWhiteSpace(model.FunctionID)) { foreach (var rid in model.FunctionID.Split(',')) { if (!string.IsNullOrWhiteSpace(rid)) { if (rid.Length > 1) { if (SonFunction.GetById(rid).FatherId != fatherId) { conn.Execute( "Insert into rolefunction values (@RoleId,@FunctionId)", new RoleFunctionDto { RoleId = model.RoleId, FunctionID = SonFunction.GetById(rid).FatherId }); fatherId = SonFunction.GetById(rid).FatherId; } } conn.Execute("Insert into rolefunction values (@RoleId,@FunctionId)", new RoleFunctionDto { RoleId = model.RoleId, FunctionID = rid }); //RoleUser.Insert(}); } } } } transaction.Commit(); } catch (Exception ex) { transaction.Rollback(); } return(result); } }
public PartialViewResult Menu() { List <ResFunctionDto> function = new List <ResFunctionDto>(); function = DapperService.Function.GetFunction().OrderBy(p => p.Index).ToList(); function.ForEach(p => { List <SonFunctionDto> son = new List <SonFunctionDto>(); if (!p.SonFionctionId.IsNullOrEmpty()) { foreach (var sonid in p.SonFionctionId.Split(',')) { if (!string.IsNullOrWhiteSpace(sonid)) { son.Add(SonFunction.GetById(sonid)); } } } p.SonFunction = son; } ); return(PartialView(function)); }