コード例 #1
0
 /// <summary>
 /// 保存实体数据(新增、修改)
 /// <param name="keyValue">主键</param>
 /// <summary>
 /// <returns></returns>
 public void SaveEntity(IMContactsEntity entity)
 {
     try
     {
         IMContactsEntity entity2 = GetEntity(entity.F_MyUserId, entity.F_OtherUserId);
         entity.F_IsRead = 2;
         if (entity2 == null)
         {
             entity.Create();
             this.BaseRepository().Insert(entity);
         }
         else
         {
             entity.Modify(entity2.F_Id);
             this.BaseRepository().Update(entity);
         }
     }
     catch (Exception ex)
     {
         if (ex is ExceptionEx)
         {
             throw;
         }
         else
         {
             throw ExceptionEx.ThrowServiceException(ex);
         }
     }
 }
コード例 #2
0
        /// <summary>
        /// 保存实体数据(新增)
        /// <param name="entity">实体数据</param>
        /// <summary>
        /// <returns></returns>
        public void SaveEntity(IMMsgEntity entity)
        {
            IMContactsEntity myContacts    = new IMContactsEntity();
            IMContactsEntity otherContacts = new IMContactsEntity();

            myContacts.F_MyUserId    = entity.F_SendUserId;
            myContacts.F_OtherUserId = entity.F_RecvUserId;
            myContacts.F_Content     = entity.F_Content;

            otherContacts.F_MyUserId    = entity.F_RecvUserId;
            otherContacts.F_OtherUserId = entity.F_SendUserId;
            otherContacts.F_Content     = entity.F_Content;

            IMContactsEntity myContactsTmp    = this.BaseRepository().FindEntity <IMContactsEntity>(t => t.F_MyUserId.Equals(myContacts.F_MyUserId) && t.F_OtherUserId.Equals(myContacts.F_OtherUserId));
            IMContactsEntity otherContactsTmp = this.BaseRepository().FindEntity <IMContactsEntity>(t => t.F_MyUserId.Equals(otherContacts.F_MyUserId) && t.F_OtherUserId.Equals(otherContacts.F_OtherUserId));
            var db = this.BaseRepository().BeginTrans();

            try
            {
                myContacts.F_IsRead = 2;
                if (myContactsTmp == null)
                {
                    myContacts.Create();
                    db.Insert(myContacts);
                }
                else
                {
                    myContacts.Modify(myContactsTmp.F_Id);
                    db.Update(myContacts);
                }

                otherContacts.F_IsRead = 1;
                if (otherContactsTmp == null)
                {
                    otherContacts.Create();
                    db.Insert(otherContacts);
                }
                else
                {
                    otherContacts.Modify(otherContactsTmp.F_Id);
                    db.Update(otherContacts);
                }

                entity.Create();
                db.Insert(entity);

                db.Commit();
            }
            catch (Exception ex)
            {
                db.Rollback();
                if (ex is ExceptionEx)
                {
                    throw;
                }
                else
                {
                    throw ExceptionEx.ThrowServiceException(ex);
                }
            }
        }