public ActionResult InputData(PollingResultView objModal, string Id) { //如果未关注企业号 if (string.IsNullOrEmpty(ViewBag.LillyId)) { return(Redirect("/notauthed.html")); } int userCount = _objResultService.GetUserCount(objModal.PollingId, ViewBag.LillyId); if (userCount > 0) { return(Json(new Result <int> { Status = 100, Message = "不能重复投票" }, JsonRequestBehavior.AllowGet)); } var currentDate = DateTime.Now; var pollingNumber = _objService.Repository.Entities.Count(x => x.Id == objModal.PollingId && x.EndDateTime < currentDate); if (pollingNumber > 0) { return(Json(new Result <int> { Status = 99, Message = "投票通道已关闭" }, JsonRequestBehavior.AllowGet)); } objModal.UserId = ViewBag.LillyId; //InsertOrUpdate(objModal, Id); var score = _objService.InsertResult(objModal); var id = objModal.PollingId; if (id != 0) { //把分数发给用户 var poll = _objService.Repository.Entities.Where(a => a.Id == id).Select(x => new { x.Type, x.AppId, x.ReplyMessage }).ToList().Select(x => new PollingEntity { Id = id, Type = x.Type, ReplyMessage = x.ReplyMessage, AppId = x.AppId }).First(); if (poll.Type == 1) { Sendmessage(id, poll, score); } } return(Json(new Result <int> { Status = 200, Data = objModal.PollingId }, JsonRequestBehavior.AllowGet)); //Json(new { rtnId = objModal.PollingId, str = "Insert Success." }, JsonRequestBehavior.AllowGet); }
protected void InsertOrUpdate(PollingResultView objModal, string Id) { if (string.IsNullOrEmpty(Id) || Id == "0") { objModal.UserId = ViewBag.lillyid; _objResultService.InsertView(objModal); } else { _objResultService.UpdateView(objModal); } }
public decimal InsertResult(PollingResultView view) { //generate results var results = view.AnswerResults.AsParallel().Select(x => new PollingResultEntity { PollingId = view.PollingId, QuestionId = x.QuestionId, QuestionName = x.QuestionName, Answer = x.Answer, AnswerText = x.AnswerText, UserId = view.UserId }); _pollingResultService.Repository.Insert(results.ToList().AsEnumerable()); var polling = GetPollingView(view.PollingId); var result = PollingResult(view.PollingId, results.ToList(), polling); //stage data var resultsAnswers = result.Select(x => { var question = polling.PollingQuestions.FirstOrDefault(a => a.Id == x.QuestionId); return(new PollingAnswerEntity { Dept1 = x.UserDeptLv1, Dept2 = x.UserDeptLv2, Dept3 = x.UserDeptLv3, LillyId = view.UserId, Name = x.UserName, QuestionId = x.QuestionId, QuestionTitle = x.QuestionTitle, RightAnswer = x.RightAnswers, SelectAnswer = x.CustomAnswer, Status = x.IsRight, Score = x.IsRight ? (question == null ? 0 : question.Score.GetValueOrDefault()) : 0, PollingId = view.PollingId }); }).ToList(); _pollingAnswerService.Repository.Insert(resultsAnswers.AsEnumerable()); var rights = result.AsParallel().Where(x => x.IsRight).ToList(); var score = polling.PollingQuestions.AsParallel().Where(x => rights.Any(y => x.Id == y.QuestionId)).Sum(x => x.Score).GetValueOrDefault(); return(score); }
private int AddOrUpdate(PollingResultView objModalSrc, bool bolAdd) { PollingResultView objView = objModalSrc; if (objView == null) { return(-1); } int iRet; var pollings = new List <PollingResultEntity>(); PollingResultEntity polling = new PollingResultEntity(); objView.AnswerResults.ToList().ForEach(x => { polling = new PollingResultEntity { PollingId = objModalSrc.PollingId, QuestionId = x.QuestionId, QuestionName = x.QuestionName, Answer = x.Answer, AnswerText = x.AnswerText, UserId = objModalSrc.UserId }; pollings.Add(polling); if (!bolAdd) { // 应为没有批量更新 iRet = Repository.Update(polling); } }); if (bolAdd) { iRet = Repository.Insert(pollings.AsEnumerable()); } return(1); }
public int UpdateView(PollingResultView objModalSrc) { return(AddOrUpdate(objModalSrc, false)); }
public new int InsertView(PollingResultView objModalSrc) { return(AddOrUpdate(objModalSrc, true)); }