Example #1
0
        public void Savephoto(string keyValue, Cadre_BaseEntity entity)
        {
            IRepository db = this.BaseRepository().BeginTrans();

            try
            {
                if (!string.IsNullOrEmpty(keyValue))
                {
                    //主表
                    entity.Modify(keyValue);
                    db.Update(entity);
                }
                else
                {
                    //主表
                    entity.Create();
                    db.Insert(entity);
                }
                db.Commit();
            }
            catch (Exception)
            {
                db.Rollback();
                throw;
            }
        }
Example #2
0
        /// <summary>
        /// 保存表单(新增、修改)
        /// </summary>
        /// <param name="keyValue">主键值</param>
        /// <param name="entity">实体对象</param>
        /// <returns></returns>
        public void SaveForm(string keyValue, Cadre_BaseEntity entity, List <Cadre_FamilyEntity> entryList)
        {
            IRepository db = this.BaseRepository().BeginTrans();

            try
            {
                if (!string.IsNullOrEmpty(keyValue))
                {
                    //主表
                    entity.Modify(keyValue);
                    db.Update(entity);
                    //明细
                    db.Delete <Cadre_FamilyEntity>(t => t.PID.Equals(keyValue));
                    foreach (Cadre_FamilyEntity item in entryList)
                    {
                        item.Create();
                        item.PID = entity.id;
                        db.Insert(item);
                    }
                }
                else
                {
                    //主表
                    entity.Create();
                    db.Insert(entity);
                    //明细
                    foreach (Cadre_FamilyEntity item in entryList)
                    {
                        item.Create();
                        item.PID = entity.id;
                        db.Insert(item);
                    }
                }
                db.Commit();
            }
            catch (Exception)
            {
                db.Rollback();
                throw;
            }
        }