0
I created a voting system, where users can give like/dislike in the chapters of books posted on the site. Follow my action:
public ActionResult Like(int id)
{
int iduser = Convert.ToInt32(Session["IDUsuario"]);
Voto v = new Voto();
if (iduser != 0)
{
v.IdUsuario = iduser;
v.IdCapitulo = id;
v.Voto1 = true;
db.Voto.Add(v);
db.SaveChanges();
return RedirectToAction("Exibir","Capitulos");
}
return View();
public ActionResult Dislike(int id)
{
int iduser = Convert.ToInt32(Session["IDUsuario"]);
Voto v = new Voto();
if (iduser != 0)
{
v.IdUsuario = iduser;
v.IdCapitulo = id;
v.Voto1 = false;
db.Voto.Add(v);
db.SaveChanges();
return RedirectToAction("Exibir","Capitulos");
}
return View();
However, I want to prevent the user from voting in the same chapter several times. Where, and how I could do this check?