Skip to content

Commit f046179

Browse files
committed
Renamed Topic.IsSaved to Topic.IsNew
In a recent commit, we introduced the new `Topic.IsSaved` property to determine if a topic mapped to a topic saved in the underlying `ITopicRepository` (1678523). This is prone to confusion because `IsSaved` could imply that the topic is an existing entity, but that its current state hasn't yet been saved. To help avoid that confusion, I've renamed it to `Topic.IsNew`. This is less ambiguous. As this has the opposite meaning of the previous property, this means flipping the `!` references.
1 parent cbba817 commit f046179

File tree

5 files changed

+18
-13
lines changed

5 files changed

+18
-13
lines changed

OnTopic.Data.Sql/SqlTopicRepository.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -392,7 +392,7 @@ SqlDateTime version
392392
/*------------------------------------------------------------------------------------------------------------------------
393393
| Establish database connection
394394
\-----------------------------------------------------------------------------------------------------------------------*/
395-
var procedureName = !topic.IsSaved? "CreateTopic" : "UpdateTopic";
395+
var procedureName = topic.IsNew? "CreateTopic" : "UpdateTopic";
396396

397397
using var command = new SqlCommand(procedureName, connection) {
398398
CommandType = CommandType.StoredProcedure
@@ -413,7 +413,7 @@ SqlDateTime version
413413
/*------------------------------------------------------------------------------------------------------------------------
414414
| Establish query parameters
415415
\-----------------------------------------------------------------------------------------------------------------------*/
416-
if (topic.IsSaved) {
416+
if (!topic.IsNew) {
417417
command.AddParameter("TopicID", topic.Id);
418418
command.AddParameter("DeleteRelationships", areReferencesResolved && areRelationshipsDirty);
419419
}
@@ -435,7 +435,7 @@ SqlDateTime version
435435
topic.Id = command.GetReturnCode();
436436

437437
Contract.Assume<InvalidOperationException>(
438-
topic.IsSaved,
438+
!topic.IsNew,
439439
"The call to the CreateTopic stored procedure did not return the expected 'Id' parameter."
440440
);
441441

@@ -605,7 +605,7 @@ private static void PersistRelations(Topic topic, SqlConnection connection) {
605605

606606
var relatedTopics = topic.Relationships.GetTopics(key);
607607
var topicId = topic.Id.ToString(CultureInfo.InvariantCulture);
608-
var savedTopics = relatedTopics.Where(t => t.IsSaved).Select<Topic, int>(m => m.Id);
608+
var savedTopics = relatedTopics.Where(t => !t.IsNew).Select<Topic, int>(m => m.Id);
609609

610610
using var targetIds = new TopicListDataTable();
611611
using var command = new SqlCommand("UpdateRelationships", connection) {

OnTopic.TestDoubles/StubTopicRepository.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ public override int Save(Topic topic, bool isRecursive = false, bool isDraft = f
115115
/*------------------------------------------------------------------------------------------------------------------------
116116
| Recurse through children
117117
\-----------------------------------------------------------------------------------------------------------------------*/
118-
if (!topic.IsSaved) {
118+
if (topic.IsNew) {
119119
topic.Id = _identity++;
120120
}
121121

OnTopic/Mapping/TopicMappingService.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -193,7 +193,7 @@ private async Task<object> MapAsync(
193193
if (cache.TryGetValue(topic.Id, out var dto)) {
194194
return dto;
195195
}
196-
else if (topic.IsSaved) {
196+
else if (!topic.IsNew) {
197197
cache.GetOrAdd(topic.Id, target);
198198
}
199199

OnTopic/Repositories/TopicRepositoryBase.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -333,7 +333,7 @@ public virtual int Save([ValidatedNotNull, NotNull]Topic topic, bool isRecursive
333333
/*----------------------------------------------------------------------------------------------------------------------
334334
| Perform reordering and/or move
335335
\---------------------------------------------------------------------------------------------------------------------*/
336-
if (topic.Parent != null && topic.Attributes.IsDirty("ParentId") && topic.IsSaved) {
336+
if (topic.Parent != null && topic.Attributes.IsDirty("ParentId") && !topic.IsNew) {
337337
var topicIndex = topic.Parent.Children.IndexOf(topic);
338338
if (topicIndex > 0) {
339339
Move(topic, topic.Parent, topic.Parent.Children[topicIndex - 1]);
@@ -347,7 +347,7 @@ public virtual int Save([ValidatedNotNull, NotNull]Topic topic, bool isRecursive
347347
| If new content type, add to cache
348348
\-----------------------------------------------------------------------------------------------------------------------*/
349349
if (
350-
!topic.IsSaved &&
350+
topic.IsNew &&
351351
topic is ContentTypeDescriptor &&
352352
_contentTypeDescriptors != null &&
353353
!_contentTypeDescriptors.Contains(topic.Key)
@@ -358,7 +358,7 @@ topic is ContentTypeDescriptor &&
358358
/*------------------------------------------------------------------------------------------------------------------------
359359
| If new attribute, refresh cache
360360
\-----------------------------------------------------------------------------------------------------------------------*/
361-
if (!topic.IsSaved && IsAttributeDescriptor(topic)) {
361+
if (topic.IsNew && IsAttributeDescriptor(topic)) {
362362
ResetAttributeDescriptors(topic);
363363
}
364364

@@ -606,7 +606,7 @@ protected IEnumerable<AttributeDescriptor> GetUnmatchedAttributes(Topic topic) {
606606
foreach (var attribute in contentType.AttributeDescriptors) {
607607

608608
// Ignore unsaved topics
609-
if (!topic.IsSaved) {
609+
if (topic.IsNew) {
610610
continue;
611611
}
612612

OnTopic/Topic.cs

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -285,16 +285,21 @@ public string? View {
285285
}
286286

287287
/*==========================================================================================================================
288-
| PROPERTY: IS SAVED
288+
| PROPERTY: IS NEW
289289
\-------------------------------------------------------------------------------------------------------------------------*/
290290
/// <summary>
291291
/// Determines whether or not the current <see cref="Topic"/> has been saved to an underlying <see
292-
/// cref="Repositories.ITopicRepository"/>.
292+
/// cref="Repositories.ITopicRepository"/>. If not, returns <c>true</c>.
293293
/// </summary>
294+
/// <remarks>
295+
/// This property does <i>not</i> reflect whether the current <i>state</i> of the topic has been saved. It <i>only</i>
296+
/// determines if the <see cref="Topic"/> maps to an existing entity in the underlying <see
297+
/// cref="Repositories.ITopicRepository"/>.
298+
/// </remarks>
294299
/// <value>
295300
/// <c>true</c> if it has been saved; otherwise, <c>false</c>.
296301
/// </value>
297-
public bool IsSaved => Id >= 0;
302+
public bool IsNew => Id < 0;
298303

299304
/*==========================================================================================================================
300305
| PROPERTY: IS HIDDEN

0 commit comments

Comments
 (0)