public void AddItem(object o) { // FIX: check if contains if (CurrentItem == null) { return; } CurrentItem.IsExpanded = true; string newItemName = (o as string).Trim(); if (String.IsNullOrEmpty(newItemName)) { return; } int newRecordId; IEntity newEntity; if (CurrentItem is CountryGroupViewModel) { newEntity = new Country(newItemName); newRecordId = RegionsDatabaseDirectory.Insert(newEntity, null); newEntity.ID = newRecordId; CurrentItem.Children.Add(new CountryViewModel(newEntity as Country)); } else if (CurrentItem is CountryViewModel) { newEntity = new Region(newItemName); newRecordId = RegionsDatabaseDirectory.Insert(newEntity, CurrentItem.Entity); newEntity.ID = newRecordId; CurrentItem.Children.Add(new RegionViewModel(newEntity as Region, CurrentItem as CountryViewModel)); } else if (CurrentItem is RegionViewModel) { newEntity = new District(newItemName); newRecordId = RegionsDatabaseDirectory.Insert(newEntity, CurrentItem.Entity); newEntity.ID = newRecordId; CurrentItem.Children.Add(new DistrictViewModel(newEntity as District, CurrentItem as RegionViewModel)); } else if (CurrentItem is DistrictViewModel) { newEntity = new City(newItemName); newRecordId = RegionsDatabaseDirectory.Insert(newEntity, CurrentItem.Entity); newEntity.ID = newRecordId; CurrentItem.Children.Add(new CityViewModel(newEntity as City, CurrentItem as DistrictViewModel)); } else if (CurrentItem is CityGroupViewModel) { CityGroupViewModel ci = CurrentItem as CityGroupViewModel; switch (ci.Name) { case "Улицы": newEntity = new Street(newItemName); newRecordId = RegionsDatabaseDirectory.Insert(newEntity, CurrentItem.Parent.Entity); newEntity.ID = newRecordId; CurrentItem.Children.Add(new StreetViewModel(newEntity as Street, ci.Parent as CityViewModel)); break; case "Районы города": newEntity = new Borough(newItemName); newRecordId = RegionsDatabaseDirectory.Insert(newEntity, CurrentItem.Parent.Entity); newEntity.ID = newRecordId; CurrentItem.Children.Add(new BoroughViewModel(newEntity as Borough, ci.Parent as CityViewModel)); break; } } else if (CurrentItem is BoroughViewModel) { newEntity = new Microdistrict(newItemName); newRecordId = RegionsDatabaseDirectory.Insert(newEntity, CurrentItem.Entity); newEntity.ID = newRecordId; CurrentItem.Children.Add(new MicrodistrictViewModel(newEntity as Microdistrict, CurrentItem as BoroughViewModel)); } }
public StreetViewModel(Street street, CityViewModel parentCity) : base(parentCity, false) { _entity = street; }