Copied to clipboard

Flag this post as spam?

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


  • Mike Beale 38 posts 132 karma points
    Jun 10, 2019 @ 09:05
    Mike Beale
    0

    Update node property from surface controller?

    Good morning,

    I've been asked to add a simple like button to pages on our intranet.

    I was thinking of adding a "likeCount" property to the document type, then calling a surface controller to update the counter.

    Is it possible for a surface controller to update a property on a node?

    If not I'll create a SQL table to hold the like counts.

    Thanks, Mike

  • Marc Goodson 2155 posts 14408 karma points MVP 9x c-trib
    Jun 10, 2019 @ 17:43
    Marc Goodson
    100

    Hi Mike

    Yes you could use the ContentService to find the page, read the likeCount property, increment by 1 and then Save it back into Umbraco.

    However I wouldn't do that, Every save, will create a new version of your content item in the Umbraco database, editors won't be able to roll back to earlier versions of the content,without losing likes! - but if lots of people like things, your db will slow down with tons of un-necessary content versions.

    If your site uses Members, then consider using Relations to create a relation between a Member and a Page object, you can count the number of Relations created, and make sure people don't like pages twice!

    If you don't have membership then yes, having the like button call an APIController that updates a custom sql table is the way to go.

    regards

    marc

  • Mike Beale 38 posts 132 karma points
    Jun 11, 2019 @ 08:04
    Mike Beale
    1

    Hi Marc,

    Thanks for the info. I was wondering if updating the node property would require a save, causing issues.

    We don't have members, yet, so it's just a simple counter for now.

    I have got it working with a separate sql table.

    Cheers, Mike

  • Marc Goodson 2155 posts 14408 karma points MVP 9x c-trib
    Jun 11, 2019 @ 08:14
    Marc Goodson
    0

    Hi Mike

    Great!, it used to be an exercise on the old Umbraco Level 2 training course I used to teach, in order to highlight pitfalls of incrementing content items via code... so your post 'took me back' a bit!

    Glad you got something working.

    regards

    Marc

Please Sign in or register to post replies

Write your reply to:

Draft