Copied to clipboard

Flag this post as spam?

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


  • Pete 13 posts 174 karma points
    Jul 17, 2024 @ 15:25
    Pete
    0

    Member saved notification

    I'm looking at creating a custom notification in umbraco 13 for when a member gets approved, so I was trying to follow this example: https://docs.umbraco.com/umbraco-cms/reference/notifications/memberservice-notifications

    However, it only has the entity that is going to be saved - is there any way to see which properties on a member entity have been changed - eg if the IsApproved has changed from false to true?

  • Pete 13 posts 174 karma points
    Jul 18, 2024 @ 12:10
    Pete
    100

    I managed to do it by using the MemberSavingNotification and using the member service to get the old member details to compare against:

    public class MemberSavingNotificationHandler : INotificationHandler<MemberSavingNotification>
    {
        private readonly Lazy<IEmailService> _emailService;
        private readonly IMemberService _memberService;
    
        public MemberSavingNotificationHandler(Lazy<IEmailService> emailService, IMemberService memberService)
        {
            _emailService = emailService;
            _memberService = memberService;
        }
    
        public void Handle(MemberSavingNotification notification)
        {
            foreach (var member in notification.SavedEntities)
            {
                if (member.IsApproved)
                {
                    var oldMember = _memberService.GetById(member.Id);
    
                    if (oldMember != null && !oldMember.IsApproved)
                    {
                        // send an email if user goes from not being approved, to being approved
                        _emailService.Value.Send(
                            member.Email,
                            "Email Subject  - Account Approved",
                            "Email Body");
                    }
                }
            }
        }
    }
    
Please Sign in or register to post replies

Write your reply to:

Draft