How to update content node from member node and vise versa
Hi
I need to pick your brain. I've got a contentnode that is linked to a membernode. If certain properties are changed on the contentnode (document), I need to update the linked membernode. Likewise, if I change properties on the membernode I need to update the linked contentnode. I know that I have to use the After_Save events on both nodes, both it would result in a loop, because they would trigger each other.
Yes, I have all member properties on a content node, including name and email, and I know it's bad practice. I have 6000+ members right now and the content section is faster to search for properties, than the member section, and I hate the way you have to define member properties in web.config and code to access them the proper way
Must admit I'm not that hardcore at C#...however I'm thinking you could perhaps avoid the loop by having a check to see if it's been more than for instance 5 seconds since either the member node or the content node was updated and then not trigger the aftersave event on the document if it's just been updated with new data from the member node and vice versa?
In my opinion the "proper way" of using the Members isn't nessecary by using the ASP.NET Membership provider. I do know that basically all methods and properties of the Umbraco Member object is marked as being obsolete. However, I think they should be reconsidered and the obsolete mark should be removed. Why? Because it's simply just that easier to work with members through the API rather than having to define every single property in the web.config.Also, I don't think the web.config is a good place to store such information, but that's another discussion ;-)
I agree that the members section is slower to work with through the API. However, with a bit of uQuery (uComponents package) you are able to optimize your member read queries a lot by using the GetMembersByXpath(string xpath) method (I think it is called) which uses xpath (surprise) instead of direct db queries.
To the problem: I think I remember asking the same question regarding the before/after state of a document in Umbraco. If I remember correct, in the after save event, the Document still contains the old values, but the Node contains the new values (or was it the other way around?) Or something to that extend! Not that much of a help right now, but I'll see if I can dig out my post for you :-)
Alternatively, you could try to new up a document object with the node id you get from the node in the after save event and debug to see which values it contains.
@Jan: I didn't think of that. It would be impossible for at person to switch from one section to another, change a value and save in under 5 seconds, and therefore it must have been done in code, and therefore no re-fire. Thanks, I'll try that
@Bo I agree that the MS way is crazy and static. I've previously used your described way, but as long that is marked obsolete, I still have my doubts. How is uComponents able to do xpath serach in the membersection, when the members are not stored in a cache file like content? I know that members are also stored as xml snippets, but it would still require a db lookup for each member - I think. Regarding the before-after values, I think it's a bit risky to compare to the Node, as that will only be updated if you "Save and publish", meaning that you could change values and save, several times and not detect all changes, because Node it not updated. I've solved this by storing the needed old-values in the HttpContext.Current.Items collection in the BeforeSave event. I then compare those values in the AfterSave event
How to update content node from member node and vise versa
Hi
I need to pick your brain. I've got a contentnode that is linked to a membernode. If certain properties are changed on the contentnode (document), I need to update the linked membernode. Likewise, if I change properties on the membernode I need to update the linked contentnode. I know that I have to use the After_Save events on both nodes, both it would result in a loop, because they would trigger each other.
Anyone got an idea to how to solve this?
Cheers
Bo
Hi Bo
May I ask why you need to keep data up to date both places? Is it the same data that needs to be updated or what's the story? :)
/Jan
No you may not ;)
Yes, I have all member properties on a content node, including name and email, and I know it's bad practice. I have 6000+ members right now and the content section is faster to search for properties, than the member section, and I hate the way you have to define member properties in web.config and code to access them the proper way
/Bo
Hi Bo
Ok, I can understand your reasons :)
Must admit I'm not that hardcore at C#...however I'm thinking you could perhaps avoid the loop by having a check to see if it's been more than for instance 5 seconds since either the member node or the content node was updated and then not trigger the aftersave event on the document if it's just been updated with new data from the member node and vice versa?
Does that make any sense?
/Jan
Hi Bo,
In my opinion the "proper way" of using the Members isn't nessecary by using the ASP.NET Membership provider. I do know that basically all methods and properties of the Umbraco Member object is marked as being obsolete. However, I think they should be reconsidered and the obsolete mark should be removed. Why? Because it's simply just that easier to work with members through the API rather than having to define every single property in the web.config.Also, I don't think the web.config is a good place to store such information, but that's another discussion ;-)
I agree that the members section is slower to work with through the API. However, with a bit of uQuery (uComponents package) you are able to optimize your member read queries a lot by using the GetMembersByXpath(string xpath) method (I think it is called) which uses xpath (surprise) instead of direct db queries.
To the problem: I think I remember asking the same question regarding the before/after state of a document in Umbraco. If I remember correct, in the after save event, the Document still contains the old values, but the Node contains the new values (or was it the other way around?) Or something to that extend! Not that much of a help right now, but I'll see if I can dig out my post for you :-)
Alternatively, you could try to new up a document object with the node id you get from the node in the after save event and debug to see which values it contains.
All the best,
Bo
@Jan: I didn't think of that. It would be impossible for at person to switch from one section to another, change a value and save in under 5 seconds, and therefore it must have been done in code, and therefore no re-fire. Thanks, I'll try that
@Bo I agree that the MS way is crazy and static. I've previously used your described way, but as long that is marked obsolete, I still have my doubts.
How is uComponents able to do xpath serach in the membersection, when the members are not stored in a cache file like content? I know that members are also stored as xml snippets, but it would still require a db lookup for each member - I think.
Regarding the before-after values, I think it's a bit risky to compare to the Node, as that will only be updated if you "Save and publish", meaning that you could change values and save, several times and not detect all changes, because Node it not updated. I've solved this by storing the needed old-values in the HttpContext.Current.Items collection in the BeforeSave event. I then compare those values in the AfterSave event
/Bo
is working on a reply...