コード例 #1
0
 public SyncStateDto Search(SyncStateDto seachDto)
 {
     try
     {
         if (null == seachDto)
         {
             throw new KnownException("对象为空,无法查询!");
         }
         if (string.IsNullOrEmpty(seachDto.UserID) && string.IsNullOrEmpty(seachDto.DeviceID))
         {
             throw new KnownException("缺少必要信息,无法查询!");
         }
         using (var db = new BCEnterpriseContext())
         {
             var query = db.SyncStates.FirstOrDefault(obj => (obj.UserID == seachDto.UserID) &&
                                                      (obj.DeviceID == seachDto.DeviceID) &&
                                                      (obj.ActionType == seachDto.ActionType));
             if (null == query)
             {
                 throw new KnownException("未能查询到相关记录!");
             }
             return(query);
         }
     }
     catch (Exception ex)
     {
         throw ex;
     }
 }
コード例 #2
0
 public int Add(SyncStateDto syncStateDto)
 {
     try
     {
         if (null == syncStateDto)
         {
             throw new KnownException("对象为空,无法添加!");
         }
         if (string.IsNullOrEmpty(syncStateDto.UserID) || string.IsNullOrEmpty(syncStateDto.DeviceID) || syncStateDto.ActionType < 0)
         {
             throw new KnownException("缺少必要信息,无法添加!");
         }
         using (var db = new BCEnterpriseContext())
         {
             syncStateDto.SyncTime = DateTime.Now;
             db.SyncStates.Add(syncStateDto);
             if (0 <= db.SaveChanges())
             {
                 throw new KnownException("添加失败!");
             }
             return(syncStateDto.SyncStateID);
         }
     }
     catch (Exception ex)
     {
         throw ex;
     }
 }
コード例 #3
0
 public bool Update(SyncStateDto updateDto)
 {
     try
     {
         if (null == updateDto)
         {
             throw new KnownException("对象为空,无法更新!");
         }
         if (string.IsNullOrEmpty(updateDto.UserID) || string.IsNullOrEmpty(updateDto.DeviceID))
         {
             throw new KnownException("缺少必要信息,无法更新!");
         }
         using (var db = new BCEnterpriseContext())
         {
             var query = db.SyncStates.FirstOrDefault(obj => (obj.UserID == updateDto.UserID) &&
                                                      (obj.DeviceID == updateDto.DeviceID) &&
                                                      (obj.ActionType == updateDto.ActionType));
             if (null == query)
             {
                 throw new KnownException("未能查询到相关记录,无法更新!");
             }
             if (query.SyncTime > updateDto.SyncTime)
             {
                 return(false);
             }
             query.SyncTime = updateDto.SyncTime;
             db.SyncStates.AddOrUpdate(query);
             if (0 <= db.SaveChanges())
             {
                 throw new KnownException("服务器更新失败!");
             }
             return(true);
         }
     }
     catch (Exception ex)
     {
         throw ex;
     }
 }