Ensure appropriate create and update dates are set on updated dictionary items to allow distinguishing between created and update for server events. (#19925)

This commit is contained in:
Andy Butland
2025-08-18 10:42:36 +01:00
committed by GitHub
parent a39bc0e269
commit a5f9bba481

View File

@@ -159,7 +159,25 @@ internal sealed class DictionaryItemService : RepositoryService, IDictionaryItem
/// <inheritdoc />
public async Task<Attempt<IDictionaryItem, DictionaryItemOperationStatus>> UpdateAsync(
IDictionaryItem dictionaryItem, Guid userKey)
=> await SaveAsync(
{
// Create and update dates aren't tracked for dictionary items. They exist on IDictionaryItem due to the
// inheritance from IEntity, but we don't store them.
// However we have logic in ServerEventSender that will provide SignalR events for created and update operations,
// where these dates are used to distinguish between the two (whether or not the entity has an identity cannot
// be used here, as these events fire after persistence when the identity is known for both creates and updates).
// So ensure we set something that can be distinguished here.
if (dictionaryItem.CreateDate == default)
{
dictionaryItem.CreateDate = DateTime.MinValue;
}
if (dictionaryItem.UpdateDate == default)
{
// TODO (V17): To align with updates of system dates, this needs to change to DateTime.UtcNow.
dictionaryItem.UpdateDate = DateTime.Now;
}
return await SaveAsync(
dictionaryItem,
() =>
{
@@ -174,6 +192,7 @@ internal sealed class DictionaryItemService : RepositoryService, IDictionaryItem
AuditType.Save,
"Update DictionaryItem",
userKey);
}
/// <inheritdoc />
public async Task<Attempt<IDictionaryItem?, DictionaryItemOperationStatus>> DeleteAsync(Guid id, Guid userKey)