Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Claushingebjerg 939 posts 2574 karma points
    Mar 22, 2018 @ 12:32
    Claushingebjerg
    0

    Delete member from Razor

    Im trying to delete a member from the frontend, letting the member delete his account.

    Im doing

    var member = Members.GetCurrentMember();
    
    if(member != null)
    {
         member.Delete();
         umbraco.library.RefreshContent();
    }   
    

    But i'm getting:
    'Umbraco.Core.Models.IPublishedContent' does not contain a definition for 'Delete' and no extension method 'Delete' accepting a first argument of type 'Umbraco.Core.Models.IPublishedContent' could be found (are you missing a using directive or an assembly reference?)

    What gives?

  • Alex Skrypnyk 6182 posts 24284 karma points MVP 8x admin c-trib
    Mar 22, 2018 @ 12:50
    Alex Skrypnyk
    100

    Hi

    Use this code:

    var member = Members.GetCurrentMember();
    
    var memberFromDatabase = ApplicationContext.Services.MemberService.GetById(member.Id);
    
    ApplicationContext.Services.MemberService.Delete(memberFromDatabase);
    

    Services are for making db changes as create, edit or remove

    Thanks,

    Alex

  • Diego 25 posts 156 karma points
    Aug 08, 2023 @ 09:20
    Diego
    0

    Hello, Is it a physical or logical deletion of the member from the database?

    Thanks

  • Claushingebjerg 939 posts 2574 karma points
    Mar 22, 2018 @ 12:56
    Claushingebjerg
    0

    Thanks

    It deletes the member all right, but throws this error:

    System.IO.IOException: The process cannot access the file 'D:\WEB\sitename.dk\www\App_Data\TEMP\ExamineIndexes\Internal\Index\write.lock' because it is being used by another process.

  • Alex Skrypnyk 6182 posts 24284 karma points MVP 8x admin c-trib
    Mar 22, 2018 @ 12:58
    Alex Skrypnyk
    0

    What line gives this error?

  • Claushingebjerg 939 posts 2574 karma points
    Mar 22, 2018 @ 13:01
    Claushingebjerg
    0

    ApplicationContext.Services.MemberService.Delete(memberFromDatabase);

  • Alex Skrypnyk 6182 posts 24284 karma points MVP 8x admin c-trib
    Mar 22, 2018 @ 13:04
    Alex Skrypnyk
    0

    Try to rebuild Examine indexes.

  • Claushingebjerg 939 posts 2574 karma points
    Mar 22, 2018 @ 13:10
    Claushingebjerg
    1

    Bingo :)

  • This forum is in read-only mode while we transition to the new forum.

    You can continue this topic on the new forum by tapping the "Continue discussion" link below.

Please Sign in or register to post replies