@@ -78,7 +78,8 @@ private static void AddTopic(SqlDataReader reader, Dictionary<int, Topic> topics
7878 /*------------------------------------------------------------------------------------------------------------------------
7979 | Establish topic
8080 \-----------------------------------------------------------------------------------------------------------------------*/
81- var current = TopicFactory . Create ( key , contentType , topicId ) ;
81+ var current = TopicFactory . Create ( key , contentType , topicId ) ;
82+
8283 topics . Add ( current . Id , current ) ;
8384
8485 /*------------------------------------------------------------------------------------------------------------------------
@@ -118,7 +119,7 @@ private static void SetIndexedAttributes(SqlDataReader reader, Dictionary<int, T
118119 /*------------------------------------------------------------------------------------------------------------------------
119120 | Identify topic
120121 \-----------------------------------------------------------------------------------------------------------------------*/
121- var current = topics [ topicId ] ;
122+ var current = topics [ topicId ] ;
122123
123124 /*------------------------------------------------------------------------------------------------------------------------
124125 | Set attribute value
@@ -228,7 +229,7 @@ private static void SetRelationships(SqlDataReader reader, Dictionary<int, Topic
228229
229230 // Fetch the related topic
230231 if ( topics . Keys . Contains ( targetTopicId ) ) {
231- related = topics [ targetTopicId ] ;
232+ related = topics [ targetTopicId ] ;
232233 }
233234
234235 // Bypass if either of the objects are missing
@@ -259,10 +260,10 @@ private static void SetDerivedTopics(Dictionary<int, Topic> topics) {
259260 | Loop through topics
260261 \-----------------------------------------------------------------------------------------------------------------------*/
261262 foreach ( var topic in topics . Values ) {
262- var derivedTopicId = topic . Attributes . GetInteger ( "TopicId" , - 1 , false , false ) ;
263+ var derivedTopicId = topic . Attributes . GetInteger ( "TopicId" , - 1 , false , false ) ;
263264 if ( derivedTopicId < 0 ) continue ;
264265 if ( topics . Keys . Contains ( derivedTopicId ) ) {
265- topic . DerivedTopic = topics [ derivedTopicId ] ;
266+ topic . DerivedTopic = topics [ derivedTopicId ] ;
266267 }
267268
268269 }
@@ -325,7 +326,7 @@ public override Topic Load(string? topicKey = null, bool isRecursive = true) {
325326 var command = new SqlCommand ( "GetTopicID" , connection ) ;
326327 int topicId ;
327328
328- command . CommandType = CommandType . StoredProcedure ;
329+ command . CommandType = CommandType . StoredProcedure ;
329330
330331 try {
331332
@@ -352,7 +353,7 @@ public override Topic Load(string? topicKey = null, bool isRecursive = true) {
352353 command . Parameters [ "@ReturnCode" ] != null ,
353354 "The call to the GetTopicID stored procedure did not return the expected 'ReturnCode' parameter."
354355 ) ;
355- topicId = Int32 . Parse ( command . Parameters [ "@ReturnCode" ] . Value . ToString ( ) , CultureInfo . InvariantCulture ) ;
356+ topicId = Int32 . Parse ( command . Parameters [ "@ReturnCode" ] . Value . ToString ( ) , CultureInfo . InvariantCulture ) ;
356357
357358 }
358359
@@ -409,7 +410,7 @@ public override Topic Load(int topicId, bool isRecursive = true) {
409410 | Execute query/reader
410411 \---------------------------------------------------------------------------------------------------------------------*/
411412 Debug . WriteLine ( "SqlTopicRepository.Load(): ExecuteNonQuery [" + DateTime . Now + "]" ) ;
412- reader = command . ExecuteReader ( ) ;
413+ reader = command . ExecuteReader ( ) ;
413414
414415 /*----------------------------------------------------------------------------------------------------------------------
415416 | Populate topics
@@ -550,7 +551,7 @@ public override Topic Load(int topicId, DateTime version) {
550551 /*----------------------------------------------------------------------------------------------------------------------
551552 | Execute query/reader
552553 \---------------------------------------------------------------------------------------------------------------------*/
553- reader = command . ExecuteReader ( ) ;
554+ reader = command . ExecuteReader ( ) ;
554555
555556 /*----------------------------------------------------------------------------------------------------------------------
556557 | Populate topic
@@ -709,7 +710,7 @@ public override int Save([NotNull]Topic topic, bool isRecursive = false, bool is
709710 extendedAttributes . Append (
710711 "<attribute key=\" " + attributeValue . Key + "\" ><![CDATA[" + attributeValue . Value + "]]></attribute>"
711712 ) ;
712- attributeValue . IsDirty = false ;
713+ attributeValue . IsDirty = false ;
713714 }
714715
715716 extendedAttributes . Append ( "</attributes>" ) ;
@@ -719,18 +720,18 @@ public override int Save([NotNull]Topic topic, bool isRecursive = false, bool is
719720 \-----------------------------------------------------------------------------------------------------------------------*/
720721 //Loop through the content type's supported attributes and add attribute to null attributes if topic does not contain it
721722 foreach ( var attribute in GetUnmatchedAttributes ( topic ) ) {
722- var record = attributes . NewRow ( ) ;
723- record [ "AttributeKey" ] = attribute . Key ;
724- record [ "AttributeValue" ] = null ;
723+ var record = attributes . NewRow ( ) ;
724+ record [ "AttributeKey" ] = attribute . Key ;
725+ record [ "AttributeValue" ] = null ;
725726 attributes . Rows . Add ( record ) ;
726727 }
727728
728729 /*------------------------------------------------------------------------------------------------------------------------
729730 | Establish database connection
730731 \-----------------------------------------------------------------------------------------------------------------------*/
731- var connection = new SqlConnection ( _connectionString ) ;
732- var command = ( SqlCommand ? ) null ;
733- var returnVal = - 1 ;
732+ var connection = new SqlConnection ( _connectionString ) ;
733+ var command = ( SqlCommand ? ) null ;
734+ var returnVal = - 1 ;
734735
735736 try {
736737
@@ -742,19 +743,14 @@ public override int Save([NotNull]Topic topic, bool isRecursive = false, bool is
742743 /*----------------------------------------------------------------------------------------------------------------------
743744 | Establish command type (insert or update)
744745 \---------------------------------------------------------------------------------------------------------------------*/
745- if ( topic . Id != - 1 ) {
746- command = new SqlCommand ( "UpdateTopic" , connection ) ;
747- }
748- else {
749- command = new SqlCommand ( "CreateTopic" , connection ) ;
750- }
751-
752- command . CommandType = CommandType . StoredProcedure ;
746+ var procedureName = topic . Id > 0 ? "CreateTopic" : "UpdateTopic" ;
747+ command = new SqlCommand ( procedureName , connection ) ;
748+ command . CommandType = CommandType . StoredProcedure ;
753749
754750 /*----------------------------------------------------------------------------------------------------------------------
755751 | SET VERSION DATETIME
756752 \---------------------------------------------------------------------------------------------------------------------*/
757- var version = DateTime . Now ;
753+ var version = DateTime . Now ;
758754
759755 /*----------------------------------------------------------------------------------------------------------------------
760756 | Establish query parameters
@@ -785,9 +781,9 @@ public override int Save([NotNull]Topic topic, bool isRecursive = false, bool is
785781 command . Parameters [ "@ReturnCode" ] != null ,
786782 "The call to the CreateTopic stored procedure did not return the expected 'ReturnCode' parameter."
787783 ) ;
788- returnVal = Int32 . Parse ( command . Parameters [ "@ReturnCode" ] . Value . ToString ( ) , CultureInfo . InvariantCulture ) ;
784+ returnVal = Int32 . Parse ( command . Parameters [ "@ReturnCode" ] . Value . ToString ( ) , CultureInfo . InvariantCulture ) ;
789785
790- topic . Id = returnVal ;
786+ topic . Id = returnVal ;
791787
792788 Contract . Assume < InvalidOperationException > (
793789 topic . Id > 0 ,
@@ -862,13 +858,13 @@ public override void Move(Topic topic, Topic target, Topic? sibling) {
862858 /*------------------------------------------------------------------------------------------------------------------------
863859 | Move in database
864860 \-----------------------------------------------------------------------------------------------------------------------*/
865- var connection = new SqlConnection ( _connectionString ) ;
866- var command = ( SqlCommand ? ) null ;
861+ var connection = new SqlConnection ( _connectionString ) ;
862+ var command = ( SqlCommand ? ) null ;
867863
868864 try {
869865
870- command = new SqlCommand ( "MoveTopic" , connection ) {
871- CommandType = CommandType . StoredProcedure
866+ command = new SqlCommand ( "MoveTopic" , connection ) {
867+ CommandType = CommandType . StoredProcedure
872868 } ;
873869
874870 // Add Parameters
@@ -928,13 +924,13 @@ public override void Delete(Topic topic, bool isRecursive = false) {
928924 /*------------------------------------------------------------------------------------------------------------------------
929925 | Delete from database
930926 \-----------------------------------------------------------------------------------------------------------------------*/
931- var connection = new SqlConnection ( _connectionString ) ;
932- SqlCommand ? command = null ;
927+ var connection = new SqlConnection ( _connectionString ) ;
928+ SqlCommand ? command = null ;
933929
934930 try {
935931
936- command = new SqlCommand ( "DeleteTopic" , connection ) {
937- CommandType = CommandType . StoredProcedure
932+ command = new SqlCommand ( "DeleteTopic" , connection ) {
933+ CommandType = CommandType . StoredProcedure
938934 } ;
939935
940936 // Add Parameters
@@ -1014,8 +1010,8 @@ private static string PersistRelations(Topic topic, SqlConnection connection, bo
10141010 } ;
10151011
10161012 foreach ( var targetTopicId in scope . Select < Topic , int > ( m => m . Id ) ) {
1017- var record = targetIds . NewRow ( ) ;
1018- record [ "TopicID" ] = targetTopicId ;
1013+ var record = targetIds . NewRow ( ) ;
1014+ record [ "TopicID" ] = targetTopicId ;
10191015 targetIds . Rows . Add ( record ) ;
10201016 }
10211017
@@ -1071,22 +1067,24 @@ private static string CreateRelationshipsXml(Topic topic) {
10711067 /*------------------------------------------------------------------------------------------------------------------------
10721068 | Create XML string container
10731069 \-----------------------------------------------------------------------------------------------------------------------*/
1074- var attributesXml = new StringBuilder ( "" ) ;
1070+ var attributesXml = new StringBuilder ( "" ) ;
10751071
10761072 /*------------------------------------------------------------------------------------------------------------------------
10771073 | Add a related XML node for each scope
10781074 \-----------------------------------------------------------------------------------------------------------------------*/
10791075 foreach ( var key in topic . Relationships . Keys ) {
1080- var scope = topic . Relationships . GetTopics ( key ) ;
1076+
1077+ var scope = topic . Relationships . GetTopics ( key ) ;
1078+
10811079 attributesXml . Append ( "<related scope=\" " ) ;
10821080 attributesXml . Append ( key ) ;
10831081 attributesXml . Append ( "\" >" ) ;
10841082
10851083 // Build out string array of related items in this scope
1086- var targetIds = new string [ scope . Count ] ;
1087- var count = 0 ;
1084+ var targetIds = new string [ scope . Count ] ;
1085+ var count = 0 ;
10881086 foreach ( var relTopic in scope ) {
1089- targetIds [ count ] = relTopic . Id . ToString ( CultureInfo . InvariantCulture ) ;
1087+ targetIds [ count ] = relTopic . Id . ToString ( CultureInfo . InvariantCulture ) ;
10901088 count ++ ;
10911089 }
10921090 attributesXml . Append ( String . Join ( "," , targetIds ) ) ;
0 commit comments