/// <summary> /// 自动生成排序编号 /// </summary> private string MaxOrderNumber(Menu parent) { using (var dbContext = new AccountDbContext()) { var orderNum = parent.Orderby; var count = dbContext.Menus.Where(o => o.ParentId == parent.ID).Count()+1; orderNum += count < 10 ? "0" + count.ToString() : count.ToString(); return orderNum; } }
/// <summary> /// 编辑保存 /// </summary> public void SaveMenu(Menu model) { string cachingKey = "ConfigFile_AdminMenuConfig"; using (var dbContext = new AccountDbContext()) { model.ParentId = model.ParentId ?? 0; if (model.ID > 0) { dbContext.Update<Menu>(model); } else { dbContext.Insert<Menu>(model); } Caching.Remove(cachingKey); //删除菜单缓存 } }
/// <summary> /// 编辑保存 /// </summary> public void SaveMenu(Menu model) { string cachingKey = "ConfigFile_AdminMenuConfig"; using (var dbContext = new AccountDbContext()) { model.ParentId = model.ParentId ?? _RootMenuId; if (model.ID > 0) { dbContext.Update<Menu>(model); } else { model.Orderby = MaxOrderNumber(model.Parent ?? GetMenu(model.ParentId.Value)); dbContext.Insert<Menu>(model); } Caching.Remove(cachingKey); //删除菜单缓存 } }