public Award Post(AwardInputModel obj) { Award award = new Award { AwardShowID = obj.AwardShowID, AwardTypeID = obj.AwardTypeID, MediaID = obj.MediaID, Name = obj.Name, Year = obj.Year }; return(_awardData.Add(award)); }
private async void BtnAdd_Click(object sender, EventArgs e) { try { int.Parse(txtYear.Text); } catch { MessageBox.Show("The year you entered is invalid!", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } if (txtName.Text == "" || txtYear.Text == "") { MessageBox.Show("Enter all the required fields!", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } if (comboAwardShow.SelectedIndex == -1 || comboAwardType.SelectedIndex == -1 || comboMovie.SelectedIndex == -1) { MessageBox.Show("Please select an Award show, and award type and a movie to assing the award to!", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } try { AwardInputModel model = new AwardInputModel { Name = txtName.Text, Year = int.Parse(txtYear.Text), AwardShowID = comboAwardShow.SelectedIndex + 1, AwardTypeID = comboAwardType.SelectedIndex + 1, MediaID = comboMovie.SelectedIndex + 1 }; var returns = await $"{Properties.Settings.Default.APIUrl}/Awards" .WithBasicAuth(APIService.Username, APIService.Password) .PostJsonAsync(model) .ReceiveJson <Award>(); MessageBox.Show("Award added successfully!", "Success", MessageBoxButtons.OK, MessageBoxIcon.Information); this.Close(); } catch (Exception ex) { MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } }