-
Notifications
You must be signed in to change notification settings - Fork 2.9k
Description
Umbraco 13.9.2
So although the documentation doesn't seem to contain this little gem for members.. (rather than the IRememberBeingDirty)
Testing it out I don't get it detecting isNew.. I think it's because we still have two events with one suppressed so even though on the face of it var isNew = member.CreateDate == member.UpdateDate; to the millisecond looks the same when looking at the ticks they are different??
perhaps var isNew = Math.Abs((entity.UpdateDate - entity.CreateDate).TotalSeconds) < 1; or some other arbitrary level of nearness?
We've resolved this via #18207 to be released in 13.8 and 15.3.
We decided against introducing PR with the
MemberCreatedNotification- mainly for consistency reasons (we don't have them on all other entities, so it's a bit odd to have them just for member). But as others have said, thanks very much for your efforts on providing that @skttl and leading us to consider how best to tackle this.Instead we've gone with adding an overload to supress specific notifications when saving members via the
IMemberService. We then use that when creating members to ensure just oneSavednotification is published.The following notification handler shows how you can use this to respond to a member being saved, determining if they were created or updated in the save operation.
using Umbraco.Cms.Core.Events; using Umbraco.Cms.Core.Models; using Umbraco.Cms.Core.Notifications; namespace Umbraco.Cms.Web.UI.Custom; public class MemberSavedNotificationHandler : INotificationHandler<MemberSavedNotification> { private readonly ILogger<MemberSavedNotificationHandler> _logger; public MemberSavedNotificationHandler(ILogger<MemberSavedNotificationHandler> logger) => _logger = logger; public void Handle(MemberSavedNotification notification) { foreach (IMember member in notification.SavedEntities) { var isNew = member.CreateDate == member.UpdateDate; _logger.LogInformation("Member {MemberId} {MemberName} was {Action}.", member.Id, member.Name, isNew ? "created" : "updated"); } } }
Originally posted by @AndyButland in #12673
This item has been added to our backlog AB#56362