private void getOrAddCity(int index) { if (index < 0) { String name = Functions.TextFormat(cities.Text); if (name.Length == 0) { throw new Exception("Miasto nie może mieć pustej nazwy"); } cities_list newCity = new cities_list() { City = name }; context.cities_list.Add(newCity); context.SaveChanges(); cities.Items.Add(new Transport() { Name = newCity.City, Id = newCity.Id }); cities.SelectedIndex = cities.Items.Count - 1; } }