Copied to clipboard

Flag this post as spam?

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


  • Simon Dingley 1474 posts 3451 karma points c-trib
    May 16, 2017 @ 14:49
    Simon Dingley
    0

    MemberService.Deleted Not Fired

    Are there any known issues with wiring up Member event handlers? I had a look on the issue tracker and didn't notice anything relevant. The issue I have is that I need to hook into the MemberService.Deleted event but it doesn't appear to be firing.

    I have it wired up as follows:

    public class MyApplication : ApplicationEventHandler
    {
        private IMyMemberService _myMemberService;
    
        public MyApplication(IMyMemberService myMemberService)
        {
            this._myMemberService = myMemberService;
        }
    
    
        protected override void ApplicationStarted(UmbracoApplicationBase umbracoApplication, ApplicationContext applicationContext)
        {
            MemberService.Deleted += MemberService_Deleted;
        }
    
        private void MemberService_Deleted(IMemberService sender, Umbraco.Core.Events.DeleteEventArgs<Umbraco.Core.Models.IMember> e)
        {
            var member = this._myMemberService.GetByUserId((int)e.DeletedEntities.FirstOrDefault().ProviderUserKey);
            this._myMemberService.Delete(member);
        }
    }
    

    Any ideas appreciated.

    Thanks

  • Alex Skrypnyk 6182 posts 24283 karma points MVP 8x admin c-trib
    May 16, 2017 @ 17:10
    Alex Skrypnyk
    0

    Hi Simon

    It looks like not related to your issue, but there are no docs about MemberService events in documentation section - https://our.umbraco.org/documentation/reference/events/

  • Asembli 86 posts 260 karma points
    Jan 13, 2020 @ 22:18
    Asembli
    0

    Hi,

    hm late reply, but anyway, I was looking for the same fn and must say that this excerpt worked for me (7.15.3)

        public class DashboardEventHandler : ApplicationEventHandler
    {
        public DashboardEventHandler()
        {
            MemberService.Deleted += this.MemberServiceDeleted;
        }
    
        private void MemberServiceDeleted(IMemberService sender, Umbraco.Core.Events.DeleteEventArgs<Umbraco.Core.Models.IMember> e)
        {
            IMemberService memberService = ApplicationContext.Current.Services.MemberService;
            foreach (var item in e.DeletedEntities)
            {
                // do something with member beeing deleted
                int memberId = item.Id;
            }
        }
    

    BTW if you work with Members section don't forget to include this patch: https://github.com/umbraco/Umbraco-CMS/issues/6283

    Regards, /Asembli

  • Samuel Racine 1 post 71 karma points
    Nov 26, 2020 @ 16:54
    Samuel Racine
    0

    Yoyoyoyo,

    Turns out that it seems that your cannot inject a dependency in this class. I did it the way Asembli did but with an injected component in the constructor and the MemberServiceDeleted method wasn't hit when deleting a member. Then I removed the injection and it worked like a charm.

    Peace,

    Sam

  • 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