private void buttonUpdateCouple_Click(object sender, EventArgs e) { API_Models.CoupleDetail couple = this.model.Couple; if (couple == null) { return; } couple.Division = (string)this.comboBoxCoupleDivision.SelectedItem; couple.Status = (string)this.comboBoxCoupleStatus.SelectedItem; if (this.dateTimePickerCoupleRetireOn.Value.Year != 1800) { couple.RetiredOn = this.dateTimePickerCoupleRetireOn.Value.ToString("yyyy-MM-dd"); } try { if (!this.apiClient.UpdateCouple(couple)) { MessageBox.Show(this.apiClient.LastApiMessage); } else { MessageBox.Show("Couple updated"); } } catch (Api.Client.Exceptions.ApiException ex) { MessageBox.Show(ex.InnerException.Message); } listBoxCouples_DoubleClick(null, null); }
private void buttonCreateRandomCouples_Click(object sender, EventArgs e) { if (this.model.Athletes.Count == 0) { return; } var men = this.model.Athletes.Where(a => a.person.Sex == "Male").ToList(); var women = this.model.Athletes.Where(a => a.person.Sex == "Female"); int total = int.Parse(this.textBoxRandomCoupleCount.Text); Random rnd = new Random(); List <string> result = new List <string>(); for (int index = 0; index < total; index++) { API_Models.PersonDetail man = this.apiClient.GetPerson(men[rnd.Next(0, men.Count() - 1)].person.Min); var others = women.Where(a => a.person.Country == man.Country); API_Models.PersonDetail woman = this.apiClient.GetPerson(others.Skip(rnd.Next(0, others.Count() - 1)).First().person.Min); API_Models.CoupleDetail couple = new API_Models.CoupleDetail() { ManMin = man.Min, WomanMin = woman.Min, Country = man.Country, Division = man.Licenses.First().Division, Status = "Active" }; try { Uri coupleUri = this.apiClient.SaveCouple(couple); result.Add(coupleUri.ToString()); } catch (Exception ex) { result.Add(ex.InnerException != null ? ex.InnerException.Message : ex.Message); } } MessageBox.Show(string.Join("\n", result)); }
private void buttonAddCouple_Click(object sender, EventArgs e) { API_Models.CoupleDetail couple = new API_Models.CoupleDetail() { Country = this.comboBoxCoupleCountry.SelectedItem.ToString(), Division = (string)this.comboBoxCoupleDivision.SelectedItem, ManMin = int.Parse(this.textBoxManMin.Text), WomanMin = int.Parse(this.textBoxWomanMin.Text), Status = (string)this.comboBoxCoupleStatus.SelectedItem, RetiredOn = this.dateTimePickerCoupleRetireOn.Value.ToString("yyyy-MM-dd") }; try { Uri coupleUri = this.apiClient.SaveCouple(couple); MessageBox.Show(string.Format("Created new couple {0}", coupleUri.ToString())); } catch (Api.Client.Exceptions.ApiException ex) { MessageBox.Show(ex.InnerException.Message); } }