2

By default, the AbpUserRole and AbpRole implement ISoftDelete. Is it possible to disable it?

I tried to do this:

[AbpAuthorize(AppPermissions.Pages_Administration_Roles_Delete)]
public async Task DeleteRole(EntityDto input)
{
    using (CurrentUnitOfWork.DisableFilter(AbpDataFilters.SoftDelete))
    {
        var role = await _roleManager.GetRoleByIdAsync(input.Id);
        var users = await UserManager.GetUsersInRoleAsync(role.Name);

        foreach (var user in users)
        {
            CheckErrors(await UserManager.RemoveFromRoleAsync(user, role.Name));
        }

        CheckErrors(await _roleManager.DeleteAsync(role));
    }
}

Although the filter is disabled in the current unit of work, it doesn't work. The entity is marked as deleted.

aaron
  • 39,695
  • 6
  • 46
  • 102
Marcos Lommez
  • 126
  • 10

1 Answers1

6

Answered in this topic: https://forum.aspnetboilerplate.com/viewtopic.php?p=6180#p6193

Data filters work on selecting data. If your entity is SoftDelete, ABP always soft-deletes it and prevents actually deleting.

You can override CancelDeletionForSoftDelete method in your DbContext and prevent cancellation conditionally.

So, like this:

protected override void CancelDeletionForSoftDelete(EntityEntry entry)
{
    if (IsSoftDeleteFilterEnabled)
    {
        base.CancelDeletionForSoftDelete(entry);
    }
}
Community
  • 1
  • 1
aaron
  • 39,695
  • 6
  • 46
  • 102