예제 #1
0
        private void SubmitVote()
        {
            SqlHelper  sqlhelper  = SqlFactory.GetSqlhelper();
            AjaxResult result     = new AjaxResult();
            string     session    = Fun.GetSession("openid");
            int        primaryKey = int.Parse(HttpContext.Current.Request.Form["voteid"]);

            if (string.IsNullOrEmpty(session))
            {
                result.ErrCode = -1;
                result.Message = "已超期,请重新进入页面";
            }
            else if (sqlhelper.Count <VoteDetail>("where openid='" + session + "' and datediff(dd,votedate,getdate())=0", new object[0]) > 0)
            {
                result.ErrCode = -1;
                result.Message = "您今天已投过票,无法继续投票";
            }
            else
            {
                VoteInfos infos = sqlhelper.SingleById <VoteInfos>(primaryKey);
                TimeSpan  span  = (TimeSpan)(DateTime.Now - infos.ValidStartDate);
                if (span.TotalDays < 0.0)
                {
                    result.ErrCode = -1;
                    result.Message = "该投票尚未开始";
                }
                else
                {
                    TimeSpan span2 = (TimeSpan)(DateTime.Now - infos.ValidEndDate);
                    if (span2.TotalDays > 1.0)
                    {
                        result.ErrCode = -1;
                        result.Message = "该投票已经结束";
                    }
                    else
                    {
                        string[] strArray = HttpContext.Current.Request.Form["ids"].Split(new char[] { ',' });
                        for (int i = 0; i < strArray.Length; i++)
                        {
                            VotePersons persons = sqlhelper.SingleById <VotePersons>(strArray[i]);
                            VoteDetail  detail  = new VoteDetail {
                                VoteID = primaryKey,
                                Person = persons.RealName,
                                OpenID = session
                            };
                            sqlhelper.Execute("insert into votedetail(voteid,person,openid)values(@0,@1,@2)", new object[] { primaryKey, persons.RealName, session });
                        }
                        result.ErrCode = 0;
                        result.Message = "提交成功";
                        //判断每人的中奖次数
                        if (Fun.HasBonus(session))
                        {
                            result.Tag = "enable";
                            HttpContext.Current.Session["BonusEnable"] = "1";
                        }
                    }
                }
            }
            HttpContext.Current.Response.Write(JsonConvert.SerializeObject(result));
        }
예제 #2
0
        public async Task <IActionResult> Edit(VoteDetail model)
        {
            var result = await _votesService.UpdateAsync(model);

            if (result.IsSuccess)
            {
                return(Ok(result));
            }

            return(BadRequest(result));
        }
예제 #3
0
        //public VoteViewModel GetVoteAll(int id)
        //{
        //    var vote = (from l in db.Votes
        //               where l.ID == id
        //               select new VoteViewModel()
        //               {
        //                   Description = l.Description,
        //                   EndDate = l.EndDate,
        //                   ID = l.ID,
        //                   IsLogin = l.IsLogin,
        //                   IsSingle = l.IsSingle,
        //                   StartDate = l.StartDate,
        //                   UserID = l.UserID,
        //                   VoteName = l.VoteName
        //               }).FirstOrDefault();

        //    var voteDet = (from l in db.VoteDetails
        //                  where l.VoteID == id
        //                  select new VoteDet()
        //                  {
        //                      ID = l.ID,
        //                      Name = l.Name,
        //                      VoteID = l.VoteID
        //                  }).ToList();

        //    vote.VoteDetails = voteDet;

        //    return vote;
        //}

        public BaseObject UpdateVoteDetail(VoteDetail voteDetail)
        {
            var obj = new BaseObject();
            var vd  = db.VoteDetails.Find(voteDetail.ID);

            vd.Name = voteDetail.Name;

            db.SaveChanges();
            obj.Tag = 1;

            return(obj);
        }
예제 #4
0
        public IActionResult VoteSite(VoteDetail vd)
        {
            VoteMethod vm    = new VoteMethod();
            int        i     = 0;
            string     error = "";
            int        temp  = Convert.ToInt32(HttpContext.Session.GetInt32("extraInfo"));

            i             = vm.InsertVote(vd, temp, out error);
            ViewBag.error = error;
            UserMethod um = new UserMethod();

            um.SetHasVotedToTrue(HttpContext.Session.GetString("AdminID"), out string errormsg1);
            um.SetHasVotedToTrue(HttpContext.Session.GetString("UserID"), out string errormsg);
            return(RedirectToAction("NomineesToVoteOn"));
        }
        public ActionResult VoteAction(int selectedCategory)
        {
            VoteDetail renderDetail = new VoteDetail()
            {
                LocationDetail = locationDetail,
                GradeValue     = LiveTrackHandler.getGrade(selectedCategory),
                Id             = 20
            };

            voteCollection.Add(renderDetail);
            if (IsRoadCleaned)
            {
                IsRoadCleaned = false;
            }
            return(Json(true));
        }
예제 #6
0
        public BaseObject InsertVote(Vote vote, string names)
        {
            BaseObject obj = new BaseObject();

            if (vote == null)
            {
                obj.Tag     = -1;
                obj.Message = "系统错误!";
                return(obj);
            }
            try
            {
                vote.StartDate = Convert.ToDateTime(GetDate(vote.StartDate, 1));
                vote.EndDate   = Convert.ToDateTime(GetDate(vote.EndDate, 2));
                db.Votes.Add(vote);
                db.SaveChanges();

                var listName = names.Trim(';').Split(';');
                listName = listName.Distinct().ToArray();
                foreach (var item in listName)
                {
                    var voteDetail = new VoteDetail();
                    if (!string.IsNullOrEmpty(item))
                    {
                        voteDetail.VoteID = vote.ID;
                        voteDetail.Name   = item;
                        voteDetail.Count  = 0;

                        db.VoteDetails.Add(voteDetail);
                    }
                }

                db.SaveChanges();
                obj.Tag = 1;
            }
            catch (Exception e)
            {
                obj.Tag     = -1;
                obj.Message = e.Message;
            }

            return(obj);
        }
예제 #7
0
        public async Task <OperationResponse <VoteDetail> > CreateAsync(VoteDetail model)
        {
            if (string.IsNullOrWhiteSpace(model.CandidateId))
            {
                return new OperationResponse <VoteDetail> {
                           IsSuccess = false, Message = "Candidate is required"
                }
            }
            ;

            var candidate = await _unitOfWork.Candidates.GetByIdAsync(model.CandidateId);

            if (candidate == null)
            {
                return(new OperationResponse <VoteDetail>
                {
                    IsSuccess = false,
                    Message = "Candidate cannot be found"
                });
            }


            var vote = new Vote
            {
                Name           = model.Name,
                PublishingDate = model.PublishingDate,
                Candidate      = candidate
            };

            await _unitOfWork.Votes.CreateAsync(vote);

            await _unitOfWork.CommitChangesAsync(_identity.UserId);

            model.Id = vote.Id;

            return(new OperationResponse <VoteDetail>
            {
                IsSuccess = true,
                Message = "Vote has been created successfully",
                Data = model
            });
        }
예제 #8
0
        public ActionResult Votedetails(VoteDetail model)
        {
            var IdentityNo         = Request.Form["IdentityNo"];
            List <VoteModel> votes = null;

            try
            {
                if (m_internetDc.VoteDetails.Any(h => h.IdentityNo == IdentityNo.ToString()))
                {
                    votes = new List <VoteModel>();
                    foreach (var vote in m_internetDc.VoteDetails.Where(h => h.IdentityNo == IdentityNo.ToString()).ToList())
                    {
                        votes.Add(new VoteModel(vote));
                    }
                }
                ViewData["Votes"] = votes;
            }
            catch (Exception exp)
            {}
            ViewData["Message"] = "Seçmene ait oy kaydı bulunmuyor...";
            return(View());
        }
예제 #9
0
        public BaseObject UpdateVote(Vote vote, string names)
        {
            BaseObject obj = new BaseObject();

            try
            {
                var v = db.Votes.Find(vote.ID);

                if (v == null)
                {
                    obj.Tag     = -1;
                    obj.Message = "记录不存在!";
                    return(obj);
                }

                v.Description = vote.Description;
                v.EndDate     = Convert.ToDateTime(GetDate(vote.EndDate, 2));
                v.IsLogin     = vote.IsLogin;
                v.IsSingle    = vote.IsSingle;
                v.VoteName    = vote.VoteName;

                var str      = new List <string>();
                var listName = names.Trim(';').Split(';');
                //listName = listName.Distinct().ToArray();
                foreach (var item in listName)
                {
                    str.Add(item.Split(',')[1].ToString());
                }

                //var details = db.VoteDetails.Where(m => m.VoteID == v.ID && (str.Contains(m.Name))).ToList();
                //foreach (var item in details)
                //{
                //    db.VoteDetails.Remove(item);
                //}

                //var nameList = names.Split(';');
                //nameList = nameList.Distinct().ToArray();
                foreach (var item in listName)
                {
                    var sti     = item.Split(',');
                    var id      = Convert.ToInt32(sti[0]);
                    var name    = sti[1].ToString();
                    var details = db.VoteDetails.FirstOrDefault(m => m.VoteID == v.ID && m.ID != id && (!str.Contains(m.Name)));
                    if (details != null)
                    {
                        db.VoteDetails.Remove(details);
                    }

                    if (id != 0)
                    {
                        var detail = db.VoteDetails.FirstOrDefault(m => m.ID == id);
                        if (detail == null)
                        {
                            continue;
                        }
                        detail.Name = name;
                    }
                    else
                    {
                        var detail = new VoteDetail();
                        detail.Name   = name;
                        detail.VoteID = v.ID;
                        detail.Count  = 0;

                        db.VoteDetails.Add(detail);
                    }

                    //if (!string.IsNullOrEmpty(item))
                    //{
                    //    var detail = new VoteDetail();
                    //    detail.Name = item; detail.VoteID = v.ID;
                    //    detail.Count = 0;

                    //    db.VoteDetails.Add(detail);
                    //}
                }

                db.SaveChanges();

                obj.Tag = 1;
            }
            catch (Exception e)
            {
                obj.Tag     = -1;
                obj.Message = e.Message;
            }

            return(obj);
        }
예제 #10
0
    private bool IsUserVoted(string uid, string vid)
    {
        IList all = VoteDetail.Init().GetAll("VoteUserID=" + uid + " and VoteID=" + vid, null);

        return(all.Count > 0);
    }
예제 #11
0
 public Task <OperationResponse <VoteDetail> > UpdateAsync(VoteDetail model)
 {
     throw new NotImplementedException();
 }
예제 #12
0
        public ActionResult EditDetailJson(VoteDetail voteDetail)
        {
            var result = voteService.UpdateVoteDetail(voteDetail);

            return(Json(result));
        }