EntityExtensions.cs 1.1 KB

12345678910111213141516171819202122232425262728293031323334
  1. using Abp.Domain.Entities.Auditing;
  2. using Abp.Extensions;
  3. namespace Abp.Domain.Entities
  4. {
  5. /// <summary>
  6. /// Some useful extension methods for Entities.
  7. /// </summary>
  8. public static class EntityExtensions
  9. {
  10. /// <summary>
  11. /// Check if this Entity is null of marked as deleted.
  12. /// </summary>
  13. public static bool IsNullOrDeleted(this ISoftDelete entity)
  14. {
  15. return entity == null || entity.IsDeleted;
  16. }
  17. /// <summary>
  18. /// Undeletes this entity by setting <see cref="ISoftDelete.IsDeleted"/> to false and
  19. /// <see cref="IDeletionAudited"/> properties to null.
  20. /// </summary>
  21. public static void UnDelete(this ISoftDelete entity)
  22. {
  23. entity.IsDeleted = false;
  24. if (entity is IDeletionAudited)
  25. {
  26. var deletionAuditedEntity = entity.As<IDeletionAudited>();
  27. deletionAuditedEntity.DeletionTime = null;
  28. deletionAuditedEntity.DeleterUserId = null;
  29. }
  30. }
  31. }
  32. }