/// <summary> /// 编辑菜单功能 /// </summary> /// <returns></returns> public ActionResult SysMenuBarsEdit() { string[] codes = Request.Form["MenuLimitCode"].Split(','); string[] names = Request.Form["MenuLimitName"].Split(','); string[] sorts = Request.Form["MenuLimitSort"].Split(','); string id = Request.Form["id"]; if (codes.Length != names.Length) { return(FailResult(1, "功能代码和功能名称数量不匹配!")); } if (codes.Length != sorts.Length) { return(FailResult(1, "功能代码和排序数量不匹配!")); } int sort = 0; for (int i = 0; i < sorts.Length; i++) { if (!Int32.TryParse(sorts[i], out sort)) { return(FailResult(1, "排序自动只能是数字")); } } using (EFContext db = new Repositories.EFContext()) { var dbContextTransaction = db.Database.BeginTransaction(); try { // 删除菜单权限 db.Database.ExecuteSqlCommand("delete SysRoleMenuLimit where MenuLimitID in (select MenuLimitID from SysMenuLimit where MenuLimitCode <> 'view' and MenuID = {0})", id); db.Database.ExecuteSqlCommand("delete SysMenuLimit where MenuLimitCode <> 'view' and MenuID = {0}", id); for (int i = 0; i < codes.Length; i++) { Model.SysMenuLimit mlModel = new Model.SysMenuLimit() { MenuID = Int32.Parse(id), MenuLimitModified = DateTime.Now, MenuLimitCreate = DateTime.Now, MenuLimitCode = codes[i], MenuLimitName = names[i], MenuLimitSort = Int32.Parse(sorts[i]) }; db.SysMenuLimit.Add(mlModel); } db.SaveChanges(); dbContextTransaction.Commit(); } catch (Exception ex) { dbContextTransaction.Rollback(); return(FailResult(1, ex.Message)); } finally { dbContextTransaction.Dispose(); } return(SuccessResult("保存成功")); } }
/// <summary> /// 给菜单添加查看权限的bar /// 当新增一个菜单的时候,给菜单添加一个查询的功能。 /// </summary> /// <param name="id"></param> protected void AddMenuViewBar(int id) { using (EFContext db = new Repositories.EFContext()) { Model.SysMenuLimit limit = new Model.SysMenuLimit() { MenuID = id, MenuLimitModified = DateTime.Now, MenuLimitCreate = DateTime.Now, MenuLimitCode = "view", MenuLimitName = "查看", MenuLimitSort = 0 }; db.SysMenuLimit.Add(limit); db.SaveChanges(); } }