Пример #1
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;
        }
Пример #2
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;
        }
Пример #3
0
        public List<ObModelInfo> GetList(ObModelQuery query, out ListAttrInfo listAttr, out string msg)
        {
            List<ObModelInfo> list = null;
            try
            {
                if (!query.CheckPagingAttrs(MIN_PAGESIZE, MAX_PAGESIZE, out msg))
                {
                    listAttr = null;
                    return null;
                }

                ObModelDA da = new ObModelDA();
                list = da.SelectList(query, out listAttr);
                if (list == null)
                {
                    msg = "获取" + ENTITY_STR + "列表为空";
                    listAttr = null;
                    return null;
                }
            }
            catch (Exception ex)
            {
                msg = "获取" + ENTITY_STR + "列表异常";
                Logger.Error(ex, msg);
                listAttr = null;
                return null;
            }
            return list;
        }
Пример #4
0
 /// <summary>
 /// 获取记录(根据记录ID和用户ID)
 /// </summary>
 /// <param name="obId"></param>
 /// <param name="userId"></param>
 /// <param name="msg"></param>
 /// <returns></returns>
 public ObModelInfo GetEntity(long obId, long userId, out string msg)
 {
     ObModelInfo ei = null;
     try
     {
         ObModelDA da = new ObModelDA();
         ei = da.SelectByUserId(obId, userId);
         if (ei == null)
         {
             msg = "获取" + ENTITY_STR + "记录为空";
             return null;
         }
     }
     catch (Exception ex)
     {
         msg = "获取" + ENTITY_STR + "记录异常";
         Logger.Error(ex, msg);
         return null;
     }
     msg = "";
     return ei;
 }
Пример #5
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;
 }
Пример #6
0
        /// <summary>
        /// 添加实体方法
        /// </summary>
        /// <param name="entity"></param>
        /// <param name="msg"></param>
        /// <returns></returns>
        public ObModelInfo AddEntity(ObModelInfo entity, out string msg)
        {
            ObModelInfo ei = null;
            try
            {
                //验证必要的属性值
                if (!Verify(entity, out msg))
                {
                    return null;
                }
                //判断是否已存在(如同名)
                /* 对于同一userId只能有一条记录的情况
                 * 在DA类增加 SelectByUserId(entity.UserId.Value) 方法,然后进行判断即可
                 *
                */
                ObModelDA da = new ObModelDA();
                ei = da.SelectByName(entity.ObName.Value);
                if (ei != null)
                {
                    msg = "obName已存在";
                    return null;
                }

                //设置必要的空值属性初始值(对于数据库表字段要求 NOT NULL 的都必须设置)
                ei = entity;
                if (entity.ObDescri.IsNullOrWhiteSpace)
                    ei.ObDescri.Set("");
                if (entity.ObEnabled.IsNull)
                    ei.ObEnabled.Set(false);
                if (entity.ObLevel.IsNull || entity.ObLevel.Value < 0)
                    ei.ObLevel.Set(0);
                if (entity.ObMoney.IsNull || entity.ObMoney.Value < 0.0m)
                    ei.ObMoney.Set(0.0m);
                if (entity.ObScore.IsNull || entity.ObScore.Value < 0.0d)
                    ei.ObScore.Set(60.0d);
                ei.ObCreated.Now(); //设置当前日期时间
                ei.Save();  //保存实体(新增记录)
            }
            catch (Exception ex)
            {
                msg = "添加" + ENTITY_STR + "异常";
                Logger.Error(ex, msg);
                return null;
            }
            msg = "";
            return ei;
        }