示例#1
0
        /// <summary>
        /// 新增数据
        /// </summary>
        public AjaxResult Insert(TbSafeCheck model, List <TbSafeCheckItem> items, bool isApi = false)
        {
            if (model == null)
            {
                return(AjaxResult.Warning("参数错误"));
            }
            model.InsertUserCode = model.InsertUserCode;
            model.Examinestatus  = "未发起";

            try
            {
                using (DbTrans trans = Db.Context.BeginTransaction())
                {
                    //添加信息
                    Repository <TbSafeCheck> .Insert(trans, model, isApi);

                    //添加明细信息
                    Repository <TbSafeCheckItem> .Insert(trans, items, isApi);

                    trans.Commit();
                    return(AjaxResult.Success());
                }
            }
            catch (Exception ex)
            {
                return(AjaxResult.Error());
            }
        }
示例#2
0
        /// <summary>
        /// 修改数据
        /// </summary>
        public AjaxResult Update(TbSafeCheck model, List <TbSafeCheckItem> items, bool isApi = false)
        {
            if (model == null)
            {
                return(AjaxResult.Warning("参数错误"));
            }
            var anyRet = AnyInfo(model.ID);

            if (anyRet.state != ResultType.success.ToString())
            {
                return(anyRet);
            }
            try
            {
                using (DbTrans trans = Db.Context.BeginTransaction())//使用事务
                {
                    //修改信息
                    Repository <TbSafeCheck> .Update(trans, model, p => p.ID == model.ID, isApi);

                    if (items.Count > 0)
                    {
                        //删除历史明细信息
                        Repository <TbSafeCheckItem> .Delete(p => p.SafeCheckCode == model.SafeCheckCode, isApi);

                        //添加明细信息
                        Repository <TbSafeCheckItem> .Insert(trans, items, isApi);
                    }
                    trans.Commit();//提交事务

                    return(AjaxResult.Success());
                }
            }
            catch (Exception ex)
            {
                return(AjaxResult.Error(ex.ToString()));
            }
        }