Skip to content

Commit 36ca32d

Browse files
committed
Introduced isNew variable
The local `isNew` variable is more semantically meaningful and less repetitive than checking `topic.Id != -1` multiple times.
1 parent 0f7b917 commit 36ca32d

1 file changed

Lines changed: 4 additions & 7 deletions

File tree

OnTopic.Data.Sql/SqlTopicRepository.cs

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -330,26 +330,23 @@ public override int Save([NotNull]Topic topic, bool isRecursive = false, bool is
330330
var connection = new SqlConnection(_connectionString);
331331
var procedureName = topic.Id > 0? "CreateTopic" : "UpdateTopic";
332332
var command = new SqlCommand(procedureName, connection) {
333-
CommandType = CommandType.StoredProcedure
333+
CommandType = CommandType.StoredProcedure
334334
};
335-
336-
/*------------------------------------------------------------------------------------------------------------------------
337-
| Set version
338-
\-----------------------------------------------------------------------------------------------------------------------*/
339335
var version = DateTime.Now;
336+
var isNew = topic.Id == -1;
340337

341338
/*------------------------------------------------------------------------------------------------------------------------
342339
| Establish query parameters
343340
\-----------------------------------------------------------------------------------------------------------------------*/
344-
if (topic.Id != -1) {
341+
if (!isNew) {
345342
command.AddParameter("TopicID", topic.Id);
346343
}
347344
else if (topic.Parent != null) {
348345
command.AddParameter("ParentID", topic.Parent.Id);
349346
}
350347
command.AddParameter("Version", version);
351348
command.Parameters.AddWithValue("@Attributes", attributes);
352-
if (topic.Id != -1) {
349+
if (!isNew) {
353350
command.AddParameter("DeleteRelationships", true);
354351
}
355352
command.AddParameter("ExtendedAttributes", extendedAttributes);

0 commit comments

Comments
 (0)