umbraco / Umbraco.UIBuilder.Issues

Back office UI builder for Umbraco
3 stars 2 forks source link

Event Deleted and Deleting notifications cannot obtain the Entity #30

Closed matt-tolliday-iss closed 2 years ago

matt-tolliday-iss commented 2 years ago

Describe the bug When using the events KonstruktEntityDeletingNotificationor KonstruktEntityDeletedNotification the .Entity property is of type "object" and so you cannot, as per the docs, obtain details of the Entity - it looks like it is actually a OperationResult under the hood. But you cannot cast to that as it requires a value type, i believe.

public class SubscriberDeletedEventHandler : INotificationHandler<KonstruktEntityDeletingNotification>
    {
        private readonly IMemberService _memberService;

        public void Handle(KonstruktEntityDeletingNotification notification)
        {
            var subscriber = notification.Entity.**After** as SubscriberDto;

Expected behavior (https://docs.getkonstrukt.net/advanced/events#konstruktentitydeletednotification)

Environment (please complete the following information):

mattbrailsford commented 2 years ago

Good spot. These should indeed be the entity, not the OperationResult so it needs unwrapping.

mattbrailsford commented 2 years ago

This has now been updated in an upcoming 1.2.1 patch release and will be on the unstable feed shortly.

Worth noting though is that 1.2.0 was our Umbraco v10 update which makes v10 our minimum Umbraco version dependency so upgrading to Konstrukt 1.2.1 will require you to also update Umbraco.

Also, the deleting/deleted notifications don't have a Before/After property, that's just the Save notifications so this should work as a workaround if you can't upgrade

var subscriber = ((OperationResult<object>)notification.Entity).Model as SubscriberDto;