Merge remote-tracking branch 'origin/v8/dev' into vx/feature/unicore
# Conflicts: # src/Umbraco.Abstractions/EnumerableExtensions.cs # src/Umbraco.Abstractions/Models/Entities/EntityBase.cs # src/Umbraco.Core/Models/Member.cs
This commit is contained in:
46
src/Umbraco.Core/Models/Entities/EntityExtensions.cs
Normal file
46
src/Umbraco.Core/Models/Entities/EntityExtensions.cs
Normal file
@@ -0,0 +1,46 @@
|
||||
using System;
|
||||
|
||||
namespace Umbraco.Core.Models.Entities
|
||||
{
|
||||
internal static class EntityExtensions
|
||||
{
|
||||
/// <summary>
|
||||
/// Updates the entity when it is being saved.
|
||||
/// </summary>
|
||||
internal static void UpdatingEntity(this IEntity entity)
|
||||
{
|
||||
var now = DateTime.Now;
|
||||
|
||||
// just in case
|
||||
if (entity.CreateDate == default)
|
||||
{
|
||||
entity.CreateDate = now;
|
||||
}
|
||||
|
||||
// set the update date if not already set
|
||||
if (entity.UpdateDate == default || (entity is ICanBeDirty canBeDirty && canBeDirty.IsPropertyDirty("UpdateDate") == false))
|
||||
{
|
||||
entity.UpdateDate = now;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Updates the entity when it is being saved for the first time.
|
||||
/// </summary>
|
||||
internal static void AddingEntity(this IEntity entity)
|
||||
{
|
||||
var now = DateTime.Now;
|
||||
var canBeDirty = entity as ICanBeDirty;
|
||||
|
||||
// set the create and update dates, if not already set
|
||||
if (entity.CreateDate == default || canBeDirty?.IsPropertyDirty("CreateDate") == false)
|
||||
{
|
||||
entity.CreateDate = now;
|
||||
}
|
||||
if (entity.UpdateDate == default || canBeDirty?.IsPropertyDirty("UpdateDate") == false)
|
||||
{
|
||||
entity.UpdateDate = now;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user