public void updateHost(Host host) { XElement HostElement = (from item in HostRoot.Elements() where int.Parse(item.Element("HostKey").Value) == host.HostKey select item).FirstOrDefault(); if (HostElement == null) { throw new Exception("התעודת זהות שהוזנה לא מייצגת מארח במערכת"); } HostElement.Element("name").Element("PrivateName").Value = host.PrivateName; HostElement.Element("name").Element("FamilyName").Value = host.FamilyName; HostElement.Element("MailAddress").Value = host.MailAddress; HostElement.Element("FhoneNumber").Value = host.FhoneNumber; HostElement.Element("BankAccountNumber").Value = host.BankAccountNumber.ToString(); HostElement.Element("CollectionClearance").Value = host.CollectionClearance.ToString(); HostElement.Element("BankBranchDetails").Element("Bank").Element("BankName").Value = host.BankBranchDetails.BankName; HostElement.Element("BankBranchDetails").Element("Bank").Element("BankNumber").Value = host.BankBranchDetails.BankNumber.ToString(); HostElement.Element("BankBranchDetails").Element("Address").Element("BranchAddress").Value = host.BankBranchDetails.BranchAddress; HostElement.Element("BankBranchDetails").Element("Address").Element("BranchCity").Value = host.BankBranchDetails.BranchCity; HostElement.Element("BankBranchDetails").Element("BranchNumber").Value = host.BankBranchDetails.BranchNumber.ToString(); HostRoot.Save(HostPath); }
public IEnumerable <Host> getListHosts(Func <Host, bool> predicate = null) { IEnumerable <Host> hosts = (from item in HostRoot.Elements() where getHost(long.Parse(item.Element("HostKey").Value)) != null select getHost(long.Parse(item.Element("HostKey").Value))); if (predicate == null) { return(hosts); } return(hosts.Where(predicate)); }
public bool deleteHost(long key) { XElement Hostelement; try { Hostelement = (from item in HostRoot.Elements() where int.Parse(item.Element("HostKey").Value) == key select item).FirstOrDefault(); Hostelement.Remove(); HostRoot.Save(HostPath); return(true); } catch { return(false); } }
public Host getHost(long key) { Host host; try { host = (from item in HostRoot.Elements() where int.Parse(item.Element("HostKey").Value) == key select new Host() { HostKey = long.Parse(item.Element("HostKey").Value), BankAccountNumber = int.Parse(item.Element("BankAccountNumber").Value), FamilyName = item.Element("name").Element("FamilyName").Value, PrivateName = item.Element("name").Element("PrivateName").Value, MailAddress = item.Element("MailAddress").Value, CollectionClearance = bool.Parse(item.Element("CollectionClearance").Value), FhoneNumber = item.Element("FhoneNumber").Value, BankBranchDetails = new BankBranch() { BankName = item.Element("BankBranchDetails").Element("Bank").Element("BankName").Value, BankNumber = int.Parse(item.Element("BankBranchDetails").Element("Bank").Element("BankNumber").Value), BranchAddress = item.Element("BankBranchDetails").Element("Address").Element("BranchAddress").Value, BranchCity = item.Element("BankBranchDetails").Element("Address").Element("BranchCity").Value, BranchNumber = int.Parse(item.Element("BankBranchDetails").Element("BranchNumber").Value) } }).FirstOrDefault(); } catch { host = null; } if (host == null) { throw new Exception("מספר תעודת זהות לא נכון"); } return(host); }