コード例 #1
0
        public async Task <IActionResult> UpdateElection([FromBody] UpdateElection election)
        {
            await _electionService.UpdateElectionAsync(election);

            return(Ok());
        }
コード例 #2
0
        private async void btnSave_Click(object sender, EventArgs e)
        {
            var election = new ElectionModel
            {
                Title                 = txtElectionTitle.Text,
                Description           = txtDescription.Text,
                TookPlaceOn           = dtpHappensOn.Value.Date,
                CandidatesFinalizedAt = Election?.CandidatesFinalizedAt,
                ClosedAt              = Election?.ClosedAt,
                ServerTag             = Election?.ServerTag ?? " "
            };

            if (string.IsNullOrWhiteSpace(election.Title))
            {
                MessageBox.Show($"Enter the election title.", "Election title required", MessageBoxButtons.OK, MessageBoxIcon.Error);
                txtElectionTitle.Focus();
                return;
            }


            if (Election == null)
            {
                try
                {
                    await _electionService.OpenElectionAsync(election);

                    if (_window != null)
                    {
                        await _window.LoadElectionAsync();
                    }

                    MessageBox.Show($"The { election.Title } is now officially open.", "New election opened", MessageBoxButtons.OK, MessageBoxIcon.Information);

                    Close();
                }
                catch (Exception ex)
                {
                    Logger.LogError(ex);

                    MessageBox.Show(ex.GetBaseException().Message, "PROGRAM ERROR: " + ex.Source, MessageBoxButtons.OK, MessageBoxIcon.Stop);
                }
            }
            else
            {
                try
                {
                    election.Id = Election.Id;
                    await _electionService.UpdateElectionAsync(election);

                    if (_window != null)
                    {
                        await _window.LoadElectionAsync();
                    }

                    MessageBox.Show($"The election is successfully updated", "Election updated", MessageBoxButtons.OK, MessageBoxIcon.Information);

                    Close();
                }
                catch (Exception ex)
                {
                    Logger.LogError(ex);

                    MessageBox.Show(ex.GetBaseException().Message, "PROGRAM ERROR: " + ex.Source, MessageBoxButtons.OK, MessageBoxIcon.Stop);
                }
            }
        }