public void Update(ActionRequest req, ActionResponse res) { string msg = ""; try { //权限判断一,需要登录(用户或管理员) if (!Session.IsLogin) { res.Error(VERIFY_ERROR); return; } YsMemberInfo user = Session.User; //获取登录用户信息 //权限判断二,必须是管理员 /* * if (!Session.IsAdmin) * { * res.Error(VERIFY_ERROR); * return; * } */ ObModelInfo ei = null; //解析请求参数,转换为实体类 ei = req.GetModelByNameOrFirst <ObModelInfo>(ENTITY_REQ); //解析请求参数(针对有规律的实体结构(同前缀的同构表)) //参照 : public void Add(ActionRequest req, ActionResponse res) 方法 //调用业务处理方法一(用户无关) ei = UpdateEntity(ei, out msg); /* * //调用业务处理方法二(用户相关,操作权限判断) * ei = UpdateEntity(ei, user, out msg); */ if (ei == null) { res.Error(msg); return; } //返回结果集 ActionResult ar = res.AddResult(ENTITY_RES, ENTITY_FIELDS); //定义返回结果集名称和字段名 ar.AddModel(ei); //添加结果集到ActionResult } catch (Exception ex) { msg = "ys.ObModel.update 接口调用异常"; Logger.Error(ex, msg); res.Error(msg); } }
public YsSession(string sessionKey) : base(sessionKey) { BsIAccountInfo acc = this.Account; if (acc != null && acc.AccountType.Value == AccountType.User) { MUserBL userBL = new MUserBL(); string msg; user = userBL.GetYsMemeber(acc.AccountId.Value, out msg); //获取登录用户(只获取前台用户,后台用户本类自动获取) if (user == null) return; this.account = acc; } }
public YsSession(string sessionKey) : base(sessionKey) { BsIAccountInfo acc = this.Account; if (acc != null && acc.AccountType.Value == AccountType.User) { MUserBL userBL = new MUserBL(); string msg; user = userBL.GetYsMemeber(acc.AccountId.Value, out msg); //获取登录用户(只获取前台用户,后台用户本类自动获取) if (user == null) { return; } this.account = acc; } }
/// <summary> /// 更新实体方法(用户相关) /// 1.判断是否管理员 /// 2.判断记录是否属于当前用户 /// </summary> /// <param name="entity"></param> /// <param name="user"></param> /// <param name="msg"></param> /// <returns></returns> public ObModelInfo UpdateEntity(ObModelInfo entity, YsMemberInfo user, out string msg) { ObModelInfo ei = null; try { //判断参数中是否有记录ID if (entity.ObId.IsNull) { msg = "obId不能为空"; return null; } //判断是否存在ID对应的记录 ObModelDA da = new ObModelDA(); ei = da.SelectById(entity.ObId.Value); //根据ID获取记录 //ei = OModel.GetByPk<ObModelInfo>(entity.ObId.Value); //或者:根据主键获取记录 if (ei != null) { msg = "记录不存在"; return null; } //判断是否有操作权限(管理员或用户本人) if (user != null && (!user.UserId.IsNull) && (!ei.UserId.IsNull)) { if (user.AccountType.Value != Oak.Model.AccountType.Admin) //非管理员 { if (user.UserId.Value != ei.UserId.Value) { msg = VERIFY_ERROR; return null; } } } else { msg = VERIFY_ERROR; return null; } //设置需要更新的属性值(注意与添加的代码进行区分) ei.ResetAssigned(); if (!entity.ObDescri.IsNullOrWhiteSpace) ei.ObDescri.Set(entity.ObDescri.Value); if (!entity.ObEnabled.IsNull) ei.ObEnabled.Set(entity.ObEnabled.Value); if (!entity.ObLevel.IsNull) ei.ObLevel.Set(entity.ObLevel.Value); if (!entity.ObMoney.IsNull) ei.ObMoney.Set(entity.ObMoney.Value); if (!entity.ObScore.IsNull) ei.ObScore.Set(entity.ObScore.Value); if (!ei.Update()) //保存实体(更新记录) { msg = "更新" + ENTITY_STR + "失败"; return null; } } catch (Exception ex) { msg = "更新" + ENTITY_STR + "异常"; Logger.Error(ex, msg); return null; } msg = ""; return ei; }
/// <summary> /// 更新实体方法(用户相关) /// 1.判断是否管理员 /// 2.判断记录是否属于当前用户 /// </summary> /// <param name="entity"></param> /// <param name="user"></param> /// <param name="msg"></param> /// <returns></returns> public ObModelInfo UpdateEntity(ObModelInfo entity, YsMemberInfo user, out string msg) { ObModelInfo ei = null; try { //判断参数中是否有记录ID if (entity.ObId.IsNull) { msg = "obId不能为空"; return(null); } //判断是否存在ID对应的记录 ObModelDA da = new ObModelDA(); ei = da.SelectById(entity.ObId.Value); //根据ID获取记录 //ei = OModel.GetByPk<ObModelInfo>(entity.ObId.Value); //或者:根据主键获取记录 if (ei != null) { msg = "记录不存在"; return(null); } //判断是否有操作权限(管理员或用户本人) if (user != null && (!user.UserId.IsNull) && (!ei.UserId.IsNull)) { if (user.AccountType.Value != Oak.Model.AccountType.Admin) //非管理员 { if (user.UserId.Value != ei.UserId.Value) { msg = VERIFY_ERROR; return(null); } } } else { msg = VERIFY_ERROR; return(null); } //设置需要更新的属性值(注意与添加的代码进行区分) ei.ResetAssigned(); if (!entity.ObDescri.IsNullOrWhiteSpace) { ei.ObDescri.Set(entity.ObDescri.Value); } if (!entity.ObEnabled.IsNull) { ei.ObEnabled.Set(entity.ObEnabled.Value); } if (!entity.ObLevel.IsNull) { ei.ObLevel.Set(entity.ObLevel.Value); } if (!entity.ObMoney.IsNull) { ei.ObMoney.Set(entity.ObMoney.Value); } if (!entity.ObScore.IsNull) { ei.ObScore.Set(entity.ObScore.Value); } if (!ei.Update()) //保存实体(更新记录) { msg = "更新" + ENTITY_STR + "失败"; return(null); } } catch (Exception ex) { msg = "更新" + ENTITY_STR + "异常"; Logger.Error(ex, msg); return(null); } msg = ""; return(ei); }