Developer forum

Forum » Development » Notificiation subscriber UserOnBeforeSave

Notificiation subscriber UserOnBeforeSave

Keld Gøtterup
Reply
im trying to change a value of a member property but when trying to save() i seem to end up in loop. (save -> onsave -> save ->onsave) is there a way to save the value without looping?

[Subscribe(Dynamicweb.Modules.UserManagement.Notifications.UserOnBeforeSave)]
    public class NotificationSubscriber1 : NotificationSubscriber
    {


        public override void OnNotify(string notification, NotificationArgs args)
        {
 Dynamicweb.Modules.UserManagement.UserNotificationArgs a = (Dynamicweb.Modules.UserManagement.UserNotificationArgs)args;
          
  a.Subject.Department = "hej";
           // throw new ArgumentException(groupIds);
            a.Subject.Save();
        }
}



Replies

 
Pavel Volgarev
Reply
This post has been marked as an answer
Hi Keld,

I'm pretty sure that you don't need to call "Save" in your notification subscriber because the user will be saved automatically after this notification is dispatched to all subscribers.

-- Pavel 
Votes for this answer: 0
 
Jeppe Eriksson Agger Dynamicweb Employee
Jeppe Eriksson Agger
Reply

Indeed. Pavel is correct, but if you still explicitly want to call the Save() method then you could maintain a variable in the Items cache that indicates if you've already done the save or not. If you have, simply return from the subscriber.

Not doing the save is still the best solution, though.

- Jeppe

 
Keld Gøtterup
Reply

i thought i tried, but obviously i didn't because it works like a charm.

Thanks :)

 

You must be logged in to post in the forum