Skip to content

Commit 6ec9005

Browse files
committed
LastUpdated value on control should be updated
When a control is deleted or an image is added , updated or deleted on control, LastUpdated value on control should be updated.
1 parent 1cd2d65 commit 6ec9005

File tree

1 file changed

+7
-4
lines changed

1 file changed

+7
-4
lines changed

src/Pixel.Persistence.Respository/ControlRepository.cs

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ public async Task AddOrUpdateControl(string controlDataJson)
127127
string controlId = document["ControlId"].AsString;
128128
string version = document["Version"].AsString;
129129

130-
document.Add("LastUpdated", DateTime.Now.ToUniversalTime());
130+
document.Add("LastUpdated", DateTime.UtcNow);
131131

132132
//if document already exists, replace it
133133
if (controlsCollection.CountDocuments<BsonDocument>(x => x["ApplicationId"].Equals(applicationId)
@@ -169,7 +169,8 @@ public async Task DeleteControlAsync(string applicationId, string controlId)
169169
{
170170
throw new InvalidOperationException("Control is in use across one or more projects");
171171
}
172-
var updateDefinition = Builders<BsonDocument>.Update.Set("IsDeleted", true);
172+
var updateDefinition = Builders<BsonDocument>.Update.Set("IsDeleted", true)
173+
.Set("LastUpdated", DateTime.UtcNow);
173174
await controlsCollection.FindOneAndUpdateAsync<BsonDocument>(CreateControlFilter(applicationId, controlId), updateDefinition);
174175
}
175176

@@ -189,8 +190,7 @@ public async Task AddOrUpdateControlImage(ControlImageMetaData imageMetaData, by
189190
{"controlId" , imageMetaData.ControlId },
190191
{"version", imageMetaData.Version.ToString() }
191192
}
192-
});
193-
193+
});
194194
}
195195

196196
///<inheritdoc/>
@@ -213,6 +213,9 @@ public async Task DeleteImageAsync(ControlImageMetaData imageMetaData)
213213
await imageBucket.DeleteAsync(imageFile.Id);
214214
}
215215
}
216+
217+
var updateDefinition = Builders<BsonDocument>.Update.Set("LastUpdated", DateTime.UtcNow);
218+
await controlsCollection.FindOneAndUpdateAsync<BsonDocument>(CreateControlFilter(imageMetaData.ApplicationId, imageMetaData.ControlId, imageMetaData.Version), updateDefinition);
216219
}
217220

218221
/// <summary>

0 commit comments

Comments
 (0)