public string ProccessData(List<DataVote> data) { if (data != null && Session["IsVoted"] ==null) { List<Сandidate> candidates = new List<Сandidate>(); using (var db = new DbRepository(new dbname123Entities())) { candidates = db.GetСandidate().ToList(); foreach (var el in candidates) { if (data.Where(x => x.Id == el.Id && x.Category == el.Category).FirstOrDefault() != null) { if (el.Likes == null) { el.Likes = new int(); } el.Likes++; } } db.Save(); String name = (String)Session["UserEmail"]; var user = db.context.Users.Where(x => x.Email == name).FirstOrDefault(); user.IsVoted = new int(); user.IsVoted = 1; Session["IsVoted"] = true; db.Save(); } } return "true"; }
public ActionResult Index() { if (Session["isAuth"] != null && (Boolean)Session["isAuth"] == true) { List<Сandidate> candidates = new List<Сandidate>(); using (var db = new DbRepository(new dbname123Entities())) { candidates = db.GetСandidate().ToList(); } return View(candidates); } else return RedirectToAction("Index", "Home"); }