Exemplo n.º 1
0
        private void ListBoxVotingTable_SelectedIndexChanged(object sender, EventArgs e)
        {
            if (listBoxVotingTable.Items.Count == 0)
            {
                return;
            }

            if (listBoxVotingTable.SelectedItems.Count == 0)
            {
                return;
            }

            VoteTable selItem = ((DisplayItem <VoteTable>)listBoxVotingTable.SelectedItem).Item;

            if (selItem == null)
            {
                return;
            }

            textBoxVotingTableName.Text = selItem.Name;
            textBoxInvalidVotes.Text    = selItem.InvalidVotes.ToString();
            textBoxRegistedVoters.Text  = selItem.TotalRegisted.ToString();
            foreach (object item in comboBoxCE.Items)
            {
                if (item.ToString().Equals(selItem.CE.Name, StringComparison.OrdinalIgnoreCase))
                {
                    comboBoxCE.SelectedItem = item;
                    break;
                }
            }
        }
Exemplo n.º 2
0
        private void ComboBoxVotingTable_SelectedIndexChanged(object sender, EventArgs e)
        {
            VoteTable vt = ((DisplayItem <VoteTable>)comboBoxVotingTable.SelectedItem).Item;

            textBoxInvalidVote.Text = vt.InvalidVotes.ToString();
            textBoxRegistered.Text  = vt.TotalRegisted.ToString();
        }
Exemplo n.º 3
0
        public int GetCurrentRoundPlayerVotes(int playerId)
        {
            if (VoteTable == null)
            {
                return(0);
            }

            if (VoteTable.ContainsKey(playerId))
            {
                return(VoteTable[playerId]);
            }

            return(0);
        }
Exemplo n.º 4
0
        public void UpdateListViewVotes(IQueryable <Region> userRegions = null)
        {
            //listViewVotes.BeginUpdate();
            //listViewVotes.Items.Clear();

            // UNDONE: _voteEntities.votes.GroupBy(v => v.idPartido).OrderBy(v => v.Key);

            foreach (Vote vote in DbContext.Votes.OrderBy(v => v.idSector))
            {
                if (vote == null)
                {
                    continue;
                }

                Partido   partido   = DbContext.Partidos.FirstOrDefault(p => p.Id == vote.idPartido);
                Sector    sector    = DbContext.Sectors.FirstOrDefault(p => p.Id == vote.idSector);
                CE        ce        = DbContext.CEs.FirstOrDefault(p => p.Id == vote.idCE);
                VoteTable voteTable = DbContext.VoteTables.FirstOrDefault(p => p.Id == vote.idVoteTable);

                if (partido == null || sector == null || ce == null || voteTable == null)
                {
                    continue;
                }

                ListViewItem lvi = new ListViewItem(partido.Name)
                {
                    SubItems = { sector.Name, ce.Name, voteTable.Name, vote.voteData.ToString() },
                    Tag      = vote
                };


                //foreach (ListViewGroup lvg in listViewVotes.Groups)
                //{
                //    if (!(lvg.Tag is Region))
                //    {
                //        continue;
                //    }

                //    if (((Region)lvg.Tag).Id == sector.RegionId)
                //    {
                //        lvi.Group = lvg;
                //        break;
                //    }

                //}
                //listViewVotes.Items.Add(lvi);
            }

            //listViewVotes.EndUpdate();
        }
Exemplo n.º 5
0
        private void ButtonAddModify_Click(object sender, EventArgs e)
        {
            if (comboBoxCE.SelectedItem == null)
            {
                MessageBox.Show("Please select a CE");
                comboBoxCE.Focus();
                return;
            }

            string votingTableName = textBoxVotingTableName.Text;

            int invalidVotes   = Convert.ToInt32(textBoxInvalidVotes.Text);
            int registedVoters = Convert.ToInt32(textBoxRegistedVoters.Text); // recensiado


            CE selCe = ((DisplayItem <CE>)comboBoxCE.SelectedItem).Item;

            voteAppEntities dbContext = DbUtils.AppEntities;

            // try select table with same name if doesn't already exits (add new one)
            // if table already exits modify the properties only


            VoteTable workingVoteTable = dbContext.VoteTables.FirstOrDefault(vt => vt.Name == votingTableName);

            if (workingVoteTable == null)
            {
                workingVoteTable = new VoteTable
                {
                    Name          = votingTableName,
                    InvalidVotes  = invalidVotes,
                    TotalRegisted = registedVoters
                };

                selCe.voteTables.Add(workingVoteTable);
            }
            else
            {
                // refresh info
                workingVoteTable.Name          = votingTableName;
                workingVoteTable.InvalidVotes  = invalidVotes;
                workingVoteTable.TotalRegisted = registedVoters;
            }

            DbUtils.AppEntities.SaveChanges();

            UpdateListBox();
        }
Exemplo n.º 6
0
        public BaseResponse CastVote(VoteTable vModel, string UserId)
        {
            var result = new BaseResponse();

            try
            {
                var internalUserId = _context.UserTable.Where(x => x.AspNetUserId == UserId).Single().Id;
                vModel.UserId = internalUserId;
                var  comment       = _context.CommentTable.Where(x => x.Id == vModel.CommentId).Single();
                bool userVoteCheck = _context.VoteTable.Any(x => x.UserId == internalUserId && x.CommentId == vModel.CommentId);
                if (userVoteCheck == false)
                {
                    comment.TotalVotes = comment.TotalVotes + 1;
                    _context.VoteTable.Add(vModel);
                    _context.SaveChanges();
                    result.Message = "OK";
                    result.Success = true;
                }
                else
                {
                    var checkVoteStatusBeforeChange = _context.VoteTable.Where(x => x.UserId == internalUserId && x.CommentId == vModel.CommentId).Single();
                    if (checkVoteStatusBeforeChange.VoteStatus != vModel.VoteStatus)
                    {
                        if (vModel.VoteStatus == true)
                        {
                            comment.TotalVotes = comment.TotalVotes + 1;
                        }
                        else
                        {
                            comment.TotalVotes = comment.TotalVotes - 1;
                        }

                        checkVoteStatusBeforeChange.VoteStatus = vModel.VoteStatus;
                        _context.SaveChanges();
                        result.Message = "Ok vote changed";
                        result.Success = true;
                    }
                }
            }
            catch (Exception ex)
            {
                result.Success = false;
                result.Message = ex.InnerException.ToString();
            }
            return(result);
        }
Exemplo n.º 7
0
        RaftEventResult StartNewElection()
        {
            VoteTable.Clear();
            Node.RaftEventListener.OnElectionStarted();
            // increment current term
            Node.PersistedState.CurrentTerm++;
            // vote for self
            ProcessVote(Node.Id);
            Node.PersistedState.VotedFor = Node.Id;
            // send request votes to all servers
            var requestVote = new RequestVote()
            {
                CandidateId = Node.Id, CandidateTerm = CurrentTerm
            };

            return(RaftEventResult.BroadcastMessage(requestVote).SetTimer(Node.RaftSettings.FollowerTimeoutFrom, Node.RaftSettings.FollowerTimeoutTo));
        }
Exemplo n.º 8
0
        private void ButtonUpdateTable_Click(object sender, EventArgs e)
        {
            if (comboBoxVotingTable.Items.Count == 0 || comboBoxVotingTable.SelectedItem == null)
            {
                return;
            }

            // validate datas
            int invalidVotes    = Convert.ToInt32(textBoxInvalidVote.Text);
            int registeredVotes = Convert.ToInt32(textBoxRegistered.Text);

            VoteTable vt = ((DisplayItem <VoteTable>)comboBoxVotingTable.SelectedItem).Item;

            vt.InvalidVotes  = invalidVotes;
            vt.TotalRegisted = registeredVotes;
            DbContext.SaveChanges();

            MessageBox.Show("Voteing table updated", "Voting table updated", MessageBoxButtons.OK, MessageBoxIcon.Information);
        }
Exemplo n.º 9
0
        public async void SubmitV(object sender, EventArgs e)
        {
            var Clicked = (Button)sender;

            if (App.LoggedinUser != null)
            {
                var V = new VoteTable();
                V.Question      = Convert.ToInt32(Question.ClassId);
                V.User          = App.LoggedinUser.ID;
                V.ChoosenOption = Convert.ToInt32(Clicked.ClassId);
                App.database.InsertVote(V);
                await DisplayAlert("Submission Successful", "Vote Submitted", "OK");
            }
            else
            {
                await DisplayAlert("Submission Unsuccessful", "Please Login to use the Vote Function", "OK");
            }
            Op1.IsEnabled = false;
            Op2.IsEnabled = false;
            Op3.IsEnabled = false;
            Op4.IsEnabled = false;
        }