public ActionResult Single(long pollId, [FromForm] long choiceId) { // does choice #choiceId belongs to poll #pollId? if (_pollChoices.Count(c => c.PollId == pollId) == 0) { TempData["ErrorMessage"] = "Wrong poll choice!"; } else { // this ip voted for this poll (any choice)? long [] choices = _pollChoices.Select(c => c.Id).ToArray(); int votesCount = _db.PollVotes1.Where(votes => votes.IpAddress == _ip && choices.Contains(votes.PollChoiceId)) .Count(); if (votesCount > 0) { TempData["ErrorMessage"] = "You can't vote more then once on this poll!"; } else { // OK to save vote _db.PollVotes1.Add(new PollVotes1() { Id = _db.NextPollVote1Id(), IpAddress = _ip, UserAgent = _ua, PollChoiceId = choiceId }); } } return(RedirectToAction("Show", "Polls")); }