예제 #1
0
        public IEnumerable <Vote> Get()
        {
            using (votedbEntities entities = new votedbEntities())

            {
                var x = entities.Votes.ToList();
                foreach (VoteDataAccess.Vote v in x)
                {
                    var vid   = v.VoteId;
                    var cname = v.CandidateName;
                    var cid   = v.CandidateId;
                    var vo    = v.Votes;

                    Vote vote = new Vote();
                    vote.CandidateId   = cid;
                    vote.CandidateName = cname;
                    vote.VoteId        = vid;
                    vote.Votes         = vo;
                    data.Add(vote);
                    Console.Write(vo.ToString(), vo);
                }
            }

            return(data);
        }
예제 #2
0
        public void Post(CastedVote val)
        {
            using (votedbEntities entities = new votedbEntities())
            {
                var  x    = entities.Votes.ToList();
                Vote vote = new Vote();
                vote.CandidateId = val.CandidateId;
                var cname = decrypt(val.CandidateName);
                vote.CandidateName = cname;
                foreach (VoteDataAccess.Vote c in x)
                {
                    if (val.CandidateId == c.CandidateId)
                    {
                        var currentVotes = c.Votes;
                        currentVotes += 1;     // Updating for adding a new vote
                        c.Votes       = currentVotes;
                    }
                }
                using (RegisterDataAccess.votingdbEntities uentities = new RegisterDataAccess.votingdbEntities())
                {
                    var y = uentities.RegisterUsers.ToList();
                    RegisterDataAccess.RegisterUser users = new RegisterDataAccess.RegisterUser();
                    foreach (RegisterDataAccess.RegisterUser u in y)
                    {
                        if (val.UserEmail == u.Email)
                        {
                            u.Voting_Status = true;
                        }
                    }
                    uentities.SaveChanges();
                    SendEmail(val.UserEmail);
                }


                //  entities.Votes.Add(vote);
                entities.SaveChanges();
            }
        }