private static bool ValidatePrivilege(DtoPrivilege entity, out string errMsg) { errMsg = ""; if (entity == null) { errMsg = "用户数据为空,很检查后重试"; return(false); } if (string.IsNullOrEmpty(entity.PrivilegeCode)) { errMsg += "权限标识不能为空;"; } if (string.IsNullOrEmpty(entity.PrivilegeName)) { errMsg += "权限姓名不能为空;"; } if (string.IsNullOrEmpty(entity.AppCode)) { errMsg += "系统标识不能为空;"; } return(string.IsNullOrEmpty(errMsg)); }
public async Task <IActionResult> Edit(string id, string appcode, string pcode, string pname) { IPrivilege model; if (string.IsNullOrEmpty(id)) { if (string.IsNullOrEmpty(appcode)) { throw new ArgumentNullException("appcode", "请先选择系统"); } model = new DtoPrivilege { AppCode = appcode, ParentCode = pcode, ParentName = pname }; } else { model = await _service.GetPrivilege(id); } return(View(model)); }
public async Task <IActionResult> Save(int type, DtoPrivilege entity) { JsonMsg msg = new JsonMsg(); try { string errMsg; bool valid = ValidatePrivilege(entity, out errMsg); if (!valid) { msg.status = -1; msg.message = errMsg; return(Json(msg)); } entity.LastModifyTime = DateTime.Now; entity.LastModifyUserId = base.UserId; entity.LastModifyUserName = base.UserId; int ret = await this._service.SavePrivilege(entity, type); if (ret > 0) { msg.status = 0; } else { msg.status = -1; msg.message = "操作不成功,请稍后重试"; } } catch (Exception ex) { msg.status = -1; msg.message = "操作不成功:" + ex.Message; } return(Json(msg)); }