public JsonResult AddMenu(Entity.Module model) { IModuleService moduleService = ServiceFactory.Create <IModuleService>(); bool hasExists = false; //如果Area,Controller,Action都不为空的时候则要检查数据库中是否已经含有这条数据 if (!string.IsNullOrWhiteSpace(model.Area) && !string.IsNullOrWhiteSpace(model.Controller) && !string.IsNullOrWhiteSpace(model.Action)) { hasExists = moduleService.Exists(t => t.LinkUrl == model.LinkUrl || (t.Area == model.Area && t.Controller == model.Controller && t.Action == model.Action) ); } if (hasExists) { return(Json(new Result(false, "添加失败,数据库中已经含有相同Area,Controller,Action的菜单"), JsonRequestBehavior.AllowGet)); } //如果数据库中没有相同的数据,则添加到数据库中 model.ParentID = string.IsNullOrEmpty(model.ParentID.ToString()) ? 0 : model.ParentID; model.CreateUserID = CurrentInfo.CurrentUser.ID; model.CreateTime = DateTime.Now; model.IsMenu = true; var addSuccess = moduleService.AddEntity(model); //返回是否成功 Result result = new Result(addSuccess != null, ResultType.Add); return(Json(result, JsonRequestBehavior.AllowGet)); }