public void SubmitRevotingVote(HttpContext context, OleDbConnection conn) { int iPrizeID = 0; Int32.TryParse(context.Request["PrizeID"], out iPrizeID); Dal.Models.Prize prize = BLL.Prize.GetPrize(iPrizeID, conn); Dal.Models.UserInfo user = (Dal.Models.UserInfo)context.Session["UserInfo"]; Dal.Models.Expert expert = BLL.Expert.GetExpertByUserID(user.UserID.Value, conn); if (prize == null || prize.IsStopVote) { context.Response.Write("当前奖项及轮次已结束投票。"); return; } OleDbTransaction tran = conn.BeginTransaction(); try { BLL.Revote revote = new Revote(); RevotePrize last = revote.GetLastRevotePrize(prize, conn, tran); bool saved = revote.SubmitRevotingVote(expert.UserID.Value, last.RevotePrizeId, conn, tran); if (saved) { tran.Commit(); context.Response.Write("提交成功!"); } else { tran.Commit(); context.Response.Write("提交错误!"); } } catch (Exception ex) { tran.Rollback(); context.Response.Write(ex.Message); } }
private void BatchRevotingVote(HttpContext context, OleDbConnection conn) { Dal.Models.UserInfo user = (Dal.Models.UserInfo)context.Session["UserInfo"]; Dal.Models.Expert expert = BLL.Expert.GetExpertByUserID(user.UserID.Value, conn); int prizeId = 0; int recommended, notRecommended; int.TryParse(context.Request["PrizeID"], out prizeId); int.TryParse(context.Request["Recommended"], out recommended); int.TryParse(context.Request["NotRecommended"], out notRecommended); Dal.Models.Prize prize = BLL.Prize.GetPrize(prizeId, conn); if (prize == null || prize.IsStopVote) { context.Response.Write("当前奖项及轮次已结束投票。"); return; } BLL.Revote revote = new Revote(); RevotePrize revotePrize = revote.GetLastRevotePrize(prize, conn); OleDbTransaction tran = conn.BeginTransaction(); try { bool saved = revote.SaveBatchRevotingVotes(revotePrize.RevotePrizeId, expert.UserID.Value, recommended, notRecommended, conn, tran); tran.Commit(); context.Response.Write(JsonConvert.SerializeObject("投票成功!")); } catch (Exception ex) { tran.Rollback(); context.Response.Write(JsonConvert.SerializeObject(ex.Message)); } }