Skip to content

Commit 6342c91

Browse files
committed
Migrated to GetInteger() where appropriate
There's no need to parse integer values for e.g. `TopicId` or `ParentId`; this can now be done using `GetInteger()`. This has the added benefit of allowing more concrete validation of e.g. `ParentId` to ensure it is actually an integer (instead of simply not null).
1 parent f0667c1 commit 6342c91

1 file changed

Lines changed: 5 additions & 5 deletions

File tree

Ignia.Topics.Data.Sql/SqlTopicRepository.cs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -190,7 +190,7 @@ private static void SetBlobAttributes(SqlDataReader reader, Dictionary<int, Topi
190190
/// Adds relationships retrieved from an individual relationship record to their associated topics.
191191
/// </summary>
192192
/// <remarks>
193-
/// Topics can be cross-referenced with each other via a many-to-many relationships.Once the topics are populated in
193+
/// Topics can be cross-referenced with each other via a many-to-many relationships. Once the topics are populated in
194194
/// memory, loop through the data to create these associations.
195195
/// </remarks>
196196
/// <param name="reader">The <see cref="System.Data.SqlClient.SqlDataReader"/> that representing the current record.</param>
@@ -213,7 +213,7 @@ private static void SetRelationships(SqlDataReader reader, Dictionary<int, Topic
213213
| Identify affected topics
214214
\-----------------------------------------------------------------------------------------------------------------------*/
215215
var current = topics[sourceTopicId];
216-
Topic related = null;
216+
var related = (Topic)null;
217217

218218
// Fetch the related topic
219219
if (topics.Keys.Contains(targetTopicId)) {
@@ -253,8 +253,8 @@ private static void SetDerivedTopics(Dictionary<int, Topic> topics) {
253253
| Loop through topics
254254
\-----------------------------------------------------------------------------------------------------------------------*/
255255
foreach (var topic in topics.Values) {
256-
var success = Int32.TryParse(topic.Attributes.GetValue("TopicId", "-1", false, false), out var derivedTopicId);
257-
if (!success || derivedTopicId < 0) continue;
256+
var derivedTopicId = topic.Attributes.GetInteger("TopicId", -1, false, false);
257+
if (derivedTopicId < 0) continue;
258258
if (topics.Keys.Contains(derivedTopicId)) {
259259
topic.DerivedTopic = topics[derivedTopicId];
260260
}
@@ -861,7 +861,7 @@ public override int Save(Topic topic, bool isRecursive = false, bool isDraft = f
861861
\-----------------------------------------------------------------------------------------------------------------------*/
862862
if (isRecursive) {
863863
foreach (var childTopic in topic.Children) {
864-
Contract.Assume(childTopic.Attributes.GetValue("ParentID") != null, "Assumes the Parent ID AttributeValue is available.");
864+
Contract.Assume(childTopic.Attributes.GetInteger("ParentID", -1) > 0, "Assumes the Parent ID AttributeValue is available.");
865865
childTopic.Attributes.SetValue("ParentID", returnVal.ToString());
866866
Save(childTopic, isRecursive, isDraft);
867867
}

0 commit comments

Comments
 (0)