5
5
\=============================================================================================================================*/
6
6
using System ;
7
7
using System . Data ;
8
+ using System . Data . SqlTypes ;
8
9
using System . Diagnostics . CodeAnalysis ;
9
10
using System . Globalization ;
10
11
using System . Linq ;
@@ -327,29 +328,27 @@ public override int Save([NotNull]Topic topic, bool isRecursive = false, bool is
327
328
/*------------------------------------------------------------------------------------------------------------------------
328
329
| Establish database connection
329
330
\-----------------------------------------------------------------------------------------------------------------------*/
331
+ var isNew = topic . Id == - 1 ;
330
332
var connection = new SqlConnection ( _connectionString ) ;
331
- var procedureName = topic . Id > 0 ? "CreateTopic" : "UpdateTopic" ;
333
+ var procedureName = isNew ? "CreateTopic" : "UpdateTopic" ;
332
334
var command = new SqlCommand ( procedureName , connection ) {
333
335
CommandType = CommandType . StoredProcedure
334
336
} ;
335
- var version = DateTime . Now ;
336
- var isNew = topic . Id == - 1 ;
337
+ var version = new SqlDateTime ( DateTime . Now ) ;
337
338
338
339
/*------------------------------------------------------------------------------------------------------------------------
339
340
| Establish query parameters
340
341
\-----------------------------------------------------------------------------------------------------------------------*/
341
342
if ( ! isNew ) {
342
343
command . AddParameter ( "TopicID" , topic . Id ) ;
344
+ command . AddParameter ( "DeleteRelationships" , true ) ;
343
345
}
344
346
else if ( topic . Parent != null ) {
345
347
command . AddParameter ( "ParentID" , topic . Parent . Id ) ;
346
348
}
347
- command . AddParameter ( "Version" , version ) ;
348
- command . Parameters . AddWithValue ( "@Attributes" , attributes ) ;
349
- if ( ! isNew ) {
350
- command . AddParameter ( "DeleteRelationships" , true ) ;
351
- }
349
+ command . AddParameter ( "Version" , version . Value ) ;
352
350
command . AddParameter ( "ExtendedAttributes" , extendedAttributes ) ;
351
+ command . Parameters . AddWithValue ( "@Attributes" , attributes ) ;
353
352
command . AddOutputParameter ( ) ;
354
353
355
354
/*------------------------------------------------------------------------------------------------------------------------
@@ -369,6 +368,8 @@ public override int Save([NotNull]Topic topic, bool isRecursive = false, bool is
369
368
370
369
PersistRelations ( topic , connection , true ) ;
371
370
371
+ topic . VersionHistory . Insert ( 0 , version . Value ) ;
372
+
372
373
}
373
374
374
375
/*------------------------------------------------------------------------------------------------------------------------
@@ -390,11 +391,6 @@ public override int Save([NotNull]Topic topic, bool isRecursive = false, bool is
390
391
attributes . Dispose ( ) ;
391
392
}
392
393
393
- /*------------------------------------------------------------------------------------------------------------------------
394
- | Add version to version history
395
- \-----------------------------------------------------------------------------------------------------------------------*/
396
- topic . VersionHistory . Insert ( 0 , version ) ;
397
-
398
394
/*------------------------------------------------------------------------------------------------------------------------
399
395
| Recurse
400
396
\-----------------------------------------------------------------------------------------------------------------------*/
0 commit comments