public ActionResult AddOrEdit(Menu model) { if (ModelState.IsValid) { if (model.Id == 0) { //创建微信菜单 var result = CreateWXMenu(model); if (!string.IsNullOrEmpty(result)) { return(Json(AjaxResult.Fail(result))); } if (model.MenuParentId > 0) { var pMenu = _menuDal.Get <Menu>(model.MenuParentId); model.MenuParentName = pMenu?.MenuName; } model.CreatedBy = CurrentUser.UserName; model.UpdatedBy = CurrentUser.UserName; _menuDal.Insert(model); } else { //创建微信菜单 var result = CreateWXMenu(model); if (!string.IsNullOrEmpty(result)) { return(Json(AjaxResult.Fail(result))); } var entity = _menuDal.Get <Menu>(model.Id); if (entity != null) { entity.MenuLevel = model.MenuLevel; entity.MenuName = model.MenuName; entity.MenuParentId = model.MenuParentId; if (model.MenuParentId > 0) { var pMenu = _menuDal.Get <Menu>(model.MenuParentId); entity.MenuParentName = pMenu?.MenuName; } entity.Url = model.Url; entity.UpdatedTime = DateTime.Now; _menuDal.Update(entity); } } return(Json(AjaxResult.Success())); } else { var erros = GetModelErrors(); return(Json(AjaxResult.Fail(erros))); } }