public ActionResult VoteSubmit(String voteCheck) { string IP = Request.ServerVariables["HTTP_X_FORWARDED_FOR"]; if (string.IsNullOrEmpty(IP)) { IP = Request.ServerVariables["REMOTE_ADDR"]; } if (string.IsNullOrEmpty(IP)) { IP = Request.UserHostAddress; } String[] VoteCon = voteCheck.Split(','); if (VoteCon.Count() > 5) { return(Json(new { success = false, message = "您选择了超过5位候选人,本次投票无效!" })); } DateTime date = DateTime.Now.Date; bidRepository br = new bidRepository(); CandidateRepository cr = new CandidateRepository(); if (!br.CheckDuplicate(IP, date)) { return(Json(new { success = false, message = "您今天已经投过票了!" })); } try { BidModel bm = new BidModel(); bm.VoterIP = IP; bm.VoteDate = DateTime.Now.Date; bm.VoteTime = DateTime.Now; bm.VoteContent = voteCheck; foreach (String s in VoteCon) { cr.BeVoted(Convert.ToInt32(s)); } br.Insert(bm); br.Save(); return(Json(new { success = true })); } catch (Exception e) { return(Json(new { success = false, message = "投票失败,请稍后重试。错误信息:" + e.Message })); } }