public void addHost(Host host) { Host tempHost = getListHosts().FirstOrDefault(host1 => host1.HostKey == host.HostKey); if (tempHost != null) { throw new Exception("יש כבר מארח עם אותו תעודת זהות"); } else { XElement HostKey = new XElement("HostKey", host.HostKey); XElement FhoneNumber = new XElement("FhoneNumber", host.FhoneNumber); XElement BankAccountNumber = new XElement("BankAccountNumber", host.BankAccountNumber); XElement PrivateName = new XElement("PrivateName", host.PrivateName); XElement FamilyName = new XElement("FamilyName", host.FamilyName); XElement name = new XElement("name", PrivateName, FamilyName); XElement MailAddress = new XElement("MailAddress", host.MailAddress); XElement CollectionClearance = new XElement("CollectionClearance", host.CollectionClearance); XElement BankNumber = new XElement("BankNumber", host.BankBranchDetails.BankNumber); XElement BankName = new XElement("BankName", host.BankBranchDetails.BankName); XElement Bank = new XElement("Bank", BankNumber, BankName); XElement BranchNumber = new XElement("BranchNumber", host.BankBranchDetails.BranchNumber); XElement BranchAddress = new XElement("BranchAddress", host.BankBranchDetails.BranchAddress); XElement BranchCity = new XElement("BranchCity", host.BankBranchDetails.BranchCity); XElement Address = new XElement("Address", BranchAddress, BranchCity); XElement BankBranchDetails = new XElement("BankBranchDetails", Bank, BranchNumber, Address); HostRoot.Add(new XElement("Host", HostKey, name, FhoneNumber, BankAccountNumber, MailAddress, CollectionClearance, BankBranchDetails)); HostRoot.Save(HostPath); } }