Reputation: 3
I made a Web Application in asp.net MVC5. In my application I have some products. On every product a logged user can press a like button. How can I disable the like button after the logged user already pressed it. I want other users to be able to press that button, but not the users which already have pressed the button.
I don't want to save in my database all the users which have liked the product because I will have to many values in my database.
Can anyone give me an advice how I should do this? At least maybe I could save something in session.
Thanks!
Upvotes: 0
Views: 155
Reputation: 900
If you're using HTML5 store it in the localstorage . It works just like session data but it will not expire when the session is over. Only when the user clears their cache from the browser it will be removed.
If you're not using HTML5 then you have to store it in a cookie via the server and set an expiration date to whenever you feel is necessary.
Nonetheless, your data will eventually become inaccurate when people clear their cache and go back to the site click like again since you're not making people log in. You cannot track who has already tracked who liked what and how many times they liked it. When that situation occurs you need to make people log in and track what they liked already via the DB but only if you really need accurate like count I would do that.
Upvotes: 1
Reputation: 6586
Just create a simple DB table called UserLikes
It can have two columns: UserId and ProductId
Whenever a user Likes a product, make an entry in the table. Then when the user is viewing the product page, if you see that entry in the table for that user and that product, disable the Like
button.
Upvotes: 5