55\=============================================================================================================================*/
66using System ;
77using System . Data ;
8+ using System . Data . SqlTypes ;
89using System . Diagnostics . CodeAnalysis ;
910using System . Globalization ;
1011using System . Linq ;
@@ -327,29 +328,27 @@ public override int Save([NotNull]Topic topic, bool isRecursive = false, bool is
327328 /*------------------------------------------------------------------------------------------------------------------------
328329 | Establish database connection
329330 \-----------------------------------------------------------------------------------------------------------------------*/
331+ var isNew = topic . Id == - 1 ;
330332 var connection = new SqlConnection ( _connectionString ) ;
331- var procedureName = topic . Id > 0 ? "CreateTopic" : "UpdateTopic" ;
333+ var procedureName = isNew ? "CreateTopic" : "UpdateTopic" ;
332334 var command = new SqlCommand ( procedureName , connection ) {
333335 CommandType = CommandType . StoredProcedure
334336 } ;
335- var version = DateTime . Now ;
336- var isNew = topic . Id == - 1 ;
337+ var version = new SqlDateTime ( DateTime . Now ) ;
337338
338339 /*------------------------------------------------------------------------------------------------------------------------
339340 | Establish query parameters
340341 \-----------------------------------------------------------------------------------------------------------------------*/
341342 if ( ! isNew ) {
342343 command . AddParameter ( "TopicID" , topic . Id ) ;
344+ command . AddParameter ( "DeleteRelationships" , true ) ;
343345 }
344346 else if ( topic . Parent != null ) {
345347 command . AddParameter ( "ParentID" , topic . Parent . Id ) ;
346348 }
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 ) ;
352350 command . AddParameter ( "ExtendedAttributes" , extendedAttributes ) ;
351+ command . Parameters . AddWithValue ( "@Attributes" , attributes ) ;
353352 command . AddOutputParameter ( ) ;
354353
355354 /*------------------------------------------------------------------------------------------------------------------------
@@ -369,6 +368,8 @@ public override int Save([NotNull]Topic topic, bool isRecursive = false, bool is
369368
370369 PersistRelations ( topic , connection , true ) ;
371370
371+ topic . VersionHistory . Insert ( 0 , version . Value ) ;
372+
372373 }
373374
374375 /*------------------------------------------------------------------------------------------------------------------------
@@ -390,11 +391,6 @@ public override int Save([NotNull]Topic topic, bool isRecursive = false, bool is
390391 attributes . Dispose ( ) ;
391392 }
392393
393- /*------------------------------------------------------------------------------------------------------------------------
394- | Add version to version history
395- \-----------------------------------------------------------------------------------------------------------------------*/
396- topic . VersionHistory . Insert ( 0 , version ) ;
397-
398394 /*------------------------------------------------------------------------------------------------------------------------
399395 | Recurse
400396 \-----------------------------------------------------------------------------------------------------------------------*/
0 commit comments