Example #1
0
        /// <summary>
        /// 更新实体方法(用户无关)
        /// </summary>
        /// <param name="entity"></param>
        /// <param name="msg"></param>
        /// <returns></returns>
        public ObModelInfo UpdateEntity(ObModelInfo entity, 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 = Obsidian.Edm.OModel.GetByPk<ObModelInfo>(entity.ObId.Value); //或者:根据主键获取记录
                if (ei != null)
                {
                    msg = "记录不存在";
                    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;
        }
Example #2
0
        /// <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;
        }
Example #3
0
 /// <summary>
 /// 获取记录(根据记录ID)
 /// </summary>
 /// <param name="obId"></param>
 /// <param name="msg"></param>
 /// <returns></returns>
 public ObModelInfo GetEntity(long obId, out string msg)
 {
     ObModelInfo ei = null;
     try
     {
         ObModelDA da = new ObModelDA();
         ei = da.SelectById(obId);
         //ei = OModel.GetByPk<ObModelInfo>(entity.ObId.Value); //或者:根据主键获取记录
         if (ei == null)
         {
             msg = "获取" + ENTITY_STR + "记录为空";
             return null;
         }
     }
     catch (Exception ex)
     {
         msg = "获取" + ENTITY_STR + "记录异常";
         Logger.Error(ex, msg);
         return null;
     }
     msg = "";
     return ei;
 }