Base solution for your next web application
Ends in:
01 DAYS
01 HRS
01 MIN
01 SEC
Open Closed

Hard delete User #8775


User avatar
0
josus created

Hi,

How can I Hard delete users? I am writing some integration tests and I need to create and delete Test data, including users.

Thanks


7 Answer(s)
  • User Avatar
    0
    ismcagdas created
    Support Team

    Hi,

    You can use HardDelete of UserRepository, see https://aspnetboilerplate.com/Pages/Documents/Data-Filters#isoftdelete

  • User Avatar
    0
    josus created

    Thanks, it is working now but I have another problem. User settings are not cascade deleted so I need to remove them before I remove the user. I found some methods to get or change settings but I don't know how to remove them.

  • User Avatar
    0
    ismcagdas created
    Support Team

    Hi @josus,

    Deleting a setting is not implemented. However, changing a setting to its default value will delete it.

  • User Avatar
    0
    josus created

    Hi!

    It is working fine using IRepository<Setting, long>.Delete(). It works like a HardDelete :-). So, one more question, When creating the users, I want some of them created with IsActive set to false. However, they are all created as active... this is my code:

    var userId = await _userRepository.InsertOrUpdateAndGetIdAsync(new User
                {
                    ...
                    IsActive = data.IsUserActive,
                    ...
                });
    

    After create I add the user to an OU (_userManager.AddToOrganizationUnit)... Could be this action activating the user again?

    Thanks!

  • User Avatar
    0
    ismcagdas created
    Support Team

    Hi @josus

    After create I add the user to an OU (_userManager.AddToOrganizationUnit)... Could be this action activating the user again?

    I don't think this because related code block doesn't change User's IsActive property, see https://github.com/aspnetboilerplate/aspnetboilerplate/blob/dev/src/Abp.ZeroCore/Authorization/Users/AbpUserManager.cs#L745

    Could you share your InsertOrUpdateAndGetIdAsync method and the test you are using this method ?

  • User Avatar
    1
    josus created

    Hi!!

    I finally found the problem. So, we have Person entity related to user, I am creating test people with a 1-1 relation with users. The Person code clock is something like this:

    var person = new Person {
        Name = "Person Name",
        ....
        User = new User {
            ...
                IsActive = false
            ...
        },
        ...
    };
    
    await _personRepository.InsertAsync(person);
    
    

    Saving the person changes the User to Active so I need to set it to false after this action.

    Now is working well.

    Thanks!

  • User Avatar
    0
    ismcagdas created
    Support Team

    Great :)