Reputation: 170
Howdie,
Having some issues with implementing a video like system in umbraco and was wondering if any uber smart people were willing to make me feel dumb(learn something) and point me in the right direction.
The problem: As I have edited properties on the documents before I decided to create a custom media type with an int “likes” property. I would then increment this if the user hasn’t liked this video before on post back or disable the button if they have.
I imagined doing something like this:
Document doc = new Document(mediaItemId);
int curValue = doc.getProperty("likes").Value;
doc.getProperty("likes").Value = (curValue + 1);
doc.Save();
http://our.umbraco.org/wiki/reference/api-cheatsheet/modifying-document-properties
The issue arose when I discovered that umbraco treats the document types and media types differently and the code I was using previously (insert code) no longer works.
Been hacking away for some time and the only two possibilities I have left I don't really want to do. The first being to create a new media item, copy over the properties and then "save over" the original in the db, the other is to create a custom table and not worry about the umbraco API.
http://our.umbraco.org/documentation/Reference/management/Media/
I am sure there has to be an easier way to do this (hoping I am being thick).
Thanks for taking the time to read and respond!
Upvotes: 0
Views: 1155
Reputation: 10400
you should be able to exactly what you've already done but replace the line:
Document doc = new Document(mediaItemId);
with
Media doc = new Media(mediaItemId);
You will of course have to make sure that your Media type has a "likes" property. This can be done in the "Settings > Media types" section of Umbraco in the same way that you can add properties to document types.
Upvotes: 1