private void btnAdd_Click(object sender, RoutedEventArgs e) { var name = tbName.Text; if (string.IsNullOrWhiteSpace(name)) { DisplayMessage("The name is required"); return; } if (!double.TryParse(tbWeight.Text, out var weight)) { DisplayMessage("Could not parse the weight"); return; } try { var animal = creator.CreateAnimal(name, weight); menagerie.AddAnimal(animal); RefreshLb(); DisplayMessage("The menagerie has a new animal!"); } catch (ArgumentOutOfRangeException ex) { DisplayMessage(ex.Message); } }
/// <summary> /// Add animals with name and animal kind to zoo /// </summary> /// <param name="animalKind">Animal`s kind</param> /// <param name="name">Animal`s name</param> public void AddAnimal(string animalKind, string name) { Animals.Add(_animalCreator.CreateAnimal(animalKind, name)); Console.WriteLine($"Added new {animalKind.ToUpper()} with name: {name}"); }