public void AddHops(Hops aHop) { var hopInRepoFound = hopses.Any(x => x.Name == aHop.Name); if (hopInRepoFound) { // Try to remove it if we find it. var hopInRepo = hopses.FirstOrDefault(x => x.Name == aHop.Name); hopses.Remove(hopInRepo); // Always add whatever has been updated. This will cause duplicate data in some situations. // This implies that name is not allowed to be changed during update. Improvement ... TODO hopses.Add(aHop); } else { hopses.Add(aHop); } Persist(); }
private void AddButton_Click(object sender, RoutedEventArgs e) { string msg = null; var h = new Hops(); h.Name = NameTextBox.Text; h.Country = CountryTextBox.Text; h.Substitutes = SubstTextBox.Text; h.Purpose = PurposeComboBox.Text; if (!ParseMaxMinAcid(h.AlphaAcid, AlphaAcidTextBox.Text)) msg = "Please state a valid float value for Alpha acid"; if (!ParseMaxMinAcid(h.BetaAcid, BetaAcidTextBox.Text)) msg = "Please state a valid float value for Beta acid"; if (!ParseMaxMinAcid(h.CoHumulone, coHumTextBox.Text)) msg = "Please state a valid float value for cohumulone"; if (msg != null) { MessageBox.Show(msg); return; } try { Repo.AddHops(h); RefreashListview(); } catch (ArgumentException ex) { MessageBox.Show(ex.Message); } // Reset GUI AddButton.Content = "Add"; NameTextBox.Text = String.Empty; coHumTextBox.Text = String.Empty; BetaAcidTextBox.Text = String.Empty; AlphaAcidTextBox.Text = String.Empty; CountryTextBox.Text = String.Empty; SubstTextBox.Text = String.Empty; PurposeComboBox.Text = String.Empty; }
public void RemoveHops(Hops aHop) { hopses.Remove(aHop); Persist(); }