Exemplo n.º 1
0
        private void listBoxParticipants_DoubleClick(object sender, EventArgs e)
        {
            ParticipantWrapper p = this.listBoxParticipants.SelectedItem as ParticipantWrapper;

            var participant = this.apiClient.GetCoupleParticipant(p.coupleParticipant.Id);

            this.model.Participant = participant;

            var country = this.model.Countries.First(co => co.country.Name == participant.Country);

            this.textBoxCoupleId.Text    = participant.CoupleId;
            this.textBoxStartNumber.Text = participant.StartNumber.ToString();
            this.comboBoxParticipantStatus.SelectedIndex = this.comboBoxParticipantStatus.Items.IndexOf(participant.Status);
        }
Exemplo n.º 2
0
        private void buttonLoadParticipants_Click(object sender, EventArgs e)
        {
            this.model.Participants.Clear();

            var competition = listBoxCompetitions.SelectedItem as CompetitionWrapper;

            DateTime    start           = DateTime.Now;
            var         allParticipants = this.apiClient.GetCoupleParticipants(competition.competition.Id);
            List <Task> tasks           = new List <Task>();

            if (allParticipants.Count == 0)
            {
                MessageBox.Show("No participants.");
                return;
            }
            foreach (var p in allParticipants)
            {
                tasks.Add(new Task(new Action <object>(state =>
                {
                    try
                    {
                        var pa = new ParticipantWrapper(this.apiClient.GetCoupleParticipant((int)state));
                        lock (this.model.Participants)
                        {
                            this.model.Participants.Add(pa);
                        }
                    }
                    catch (Exception ex)
                    {
                        Console.WriteLine(ex);
                    }
                }), p.Id));
            }

            Task.Factory.ContinueWhenAll(tasks.ToArray(), new Action <Task[]>(t =>
            {
                MessageBox.Show("All participants loaded.");
            }));

            foreach (var t in tasks)
            {
                t.Start();
            }
        }
Exemplo n.º 3
0
        private void buttonDeleteAllParticipants_Click(object sender, EventArgs e)
        {
            var competition = listBoxCompetitions.SelectedItem as CompetitionWrapper;

            List <Task> tasks = new List <Task>();

            foreach (var p in this.listBoxParticipants.Items.OfType <ParticipantWrapper>())
            {
                tasks.Add(new Task(new Action <object>(state =>
                {
                    ParticipantWrapper pa = state as ParticipantWrapper;
                    if (pa.coupleParticipant != null)
                    {
                        this.apiClient.DeleteCoupleParticipant(pa.coupleParticipant.Id);
                    }
                    lock (this.model.Participants)
                    {
                        this.model.Participants.Remove(pa);
                    }
                }), p));
            }

            if (tasks.Count == 0)
            {
                return;
            }

            foreach (var t in tasks)
            {
                t.Start();
            }

            Task.Factory.ContinueWhenAll(tasks.ToArray(), new Action <Task[]>(t =>
            {
                MessageBox.Show("All participants deleted.");
            }));
        }