public static void AddHouseAndApartment(LocalAddressDTO dto, LocalAddress address) { if (dto.NewApartment && (Apartment.FindByAddress(address).get_Count() == 0)) { if (House.FindByAddress((LocalAddress) address.Parent) == House.Null) { AddHouse((LocalAddress) address.Parent); } Apartment apartment = new Apartment { AdrId = address.Id }; apartment.SetNewNumber(); apartment.HouseId = (address.Level == AddressLevel.MaxAddress) ? address.GetParent().GetHouse().Id : address.GetHouse().Id; apartment.SaveChanges(); } if (dto.NewHouse && (House.FindByAddress(address) == House.Null)) { AddHouse(address); } }
private void AddApartmment() { if (House.FindByAddress((LocalAddress) this.SelectedAddress.Parent) == House.Null) { LocalAddress.AddHouse((LocalAddress) this.SelectedAddress.Parent); } Apartment apartment = new Apartment { AdrId = this.SelectedAddress.Id }; apartment.SetNewNumber(); apartment.HouseId = (this.SelectedAddress.Level == AddressLevel.MaxAddress) ? this.SelectedAddress.GetParent().GetHouse().Id : this.SelectedAddress.GetHouse().Id; if (Apartment.IsExistNumber(apartment.Number)) { Messages.ShowWarning("На этот адрес заведен паспорт квартиры. Попробуйте поменять номер имеющегося паспорта квартиры, чтобы избежать повторения номеров паспортов."); } else { apartment.SaveChanges(); System.Windows.Forms.TreeNode node = new System.Windows.Forms.TreeNode(apartment.ToString()); node.set_Tag(apartment); base.SelectedNode.Nodes.Add(node); base.SelectedNode.Expand(); base.set_SelectedNode(node); } }