4

i'm making a school project and the idea is: Everyone can log in an create a Suggestion. Everyone can log in and vote (upvotes/downvotes) on Suggestions.

So far i have: Created my Suggestion model:

namespace Democracy.Models
{
public class Suggestion
{
    public int SuggestionId { get; set; }
    public string Headline { get; set; }
    public string ImageUrl { get; set; }
    public string Body { get; set; }
    public int score { get; set; }
    public DateTime CreaationDate { get; set; }
    public Vote Votes { get; set; }
    }
}

and i scaffolded this so i have my controller.

now the votes... i've created a Vote model

namespace Democracy.Models
{
public class Vote
{
    public int VoteId { get; set; }
    public bool Value { get; set; }
    public string UserId { get; set; }
    }
}

Then the idea is that a user can click up/down vote on a Suggestion, but im not sure how to implement it, and something tells me im on a wrong path..

any point in the right direction will be much appreciated.

Edit: im not thinking of making upvote & downvote button on the Suggestion, then when i click "upvote" i create a vote with the userId, the suggestionId and then voteValue.. good or bad approach?

1 Answer 1

0

I would recommend checking the stakoverflow voting for questions and answers. You need to have an integer type in the value field.

public class Vote
{
    public int VoteId { get; set; }
    public int Value { get; set; }
    public string UserId { get; set; }    
}

Then on each click it will increment the number. Please use Javascript frameworks if you are comfortable with them. So on client side you can write a handler to increment the value using asynchronous update.

  • Edit: Please find my answer in below link. I have created the code there.

https://gist.github.com/MisterFantastic/2718f264c0b1ff774d33

10
  • Yes i know that i have to increment/decrement the votes... but now how to implement it with asp.net mvc and the razor engine, and i would prefter to keep javascript out of it. Jun 17, 2015 at 18:46
  • Why keep JS out of it? Asp.NET MVC is perfect for using JS. If you are not going to use JS, might as well use WebForms
    – thorkia
    Jun 17, 2015 at 18:56
  • as mentioned in my question, this is a school project and asp.net MVC 5 is the subject, so if it can be done without, i'd prefer to. Jun 17, 2015 at 19:13
  • That piece of code looks nothing like anything i've seen while coding asp.net mvc 5 with razor engine.. am i completely missing something? Jun 17, 2015 at 19:20
  • sorry about that. I have written that in webforms. I will give a razor sample Jun 17, 2015 at 19:24

Not the answer you're looking for? Browse other questions tagged or ask your own question.