public void AddHost(Host host) { if (DataSource.hosts.Any(item => host.Id == item.Id)) { throw new DuplicateWaitObjectException("This key already exists, DAL error"); } DataSource.hosts.Add(host.Clone()); DataSource_XML.SaveToXML(DataSource.hosts, hostPath); }
public void AddHost(Host host)//adds a new host { Host h = GetHost(host.ID); if (h != null) { throw new DuplicateWaitObjectException("Guest with this ID already exists!"); } DataSource.getHosts().Add(host.Clone()); }
void IDal.UpdateHost(Host host) { int Index = DataSource.HostsList.FindIndex(t => t.HostKey == host.HostKey); //מחפש את האינדקס של המארח עם אותו קוד if (Index == -1)//אם האינדקס = -1 כלומר, לא קיים מארח כזה אז המערכת תזרוק שגיאה { throw new KeyNotFoundException("The Host Does Not Exist"); } DataSource.HostsList[Index] = host.Clone();//במידה והמארח קיים נעדכן אותו }
public void UpdateHost(Host host) { var list = (from item in DataSource.hosts where host.Id == item.Id select item).FirstOrDefault <Host>(); if (list == null) { throw new KeyNotFoundException("Key not found, DAL error"); } DataSource.hosts.Remove(list); DataSource.hosts.Add(host.Clone()); DataSource_XML.SaveToXML(DataSource.hosts, hostPath); }
void IDal.AddHost(Host host) { //בודק האם המארח קיים var v = from item in DataSource.HostsList where item.HostKey == host.HostKey select item; if (v.FirstOrDefault() != null)//אם המארח קיים תזרוק שגיאה { throw new InvalidOperationException("The Host Already Exist"); } host.NumOfHostingUnits = 0; host.HostPassword = Configuration.HostPassword++; DS.DataSource.HostsList.Add(host.Clone());//אם המארח ךא קיים ניצור מארח חדש }
public Host GetHost(int hostKey) { XElement host1; host1 = (from hos in HostingUnitsRoot.Elements() where int.Parse(hos.Element("Owner").Element("HostKey").Value) == hostKey select hos).FirstOrDefault(); if (host1 == null) { throw new KeyNotFoundException("לא קיים במערכת מארח עם מפתח שמספרו" + hostKey); } List <HostingUnit> hostunits = LoadFromXML <List <HostingUnit> >(HostingUnitsPath); Host host = new Host(); foreach (var item in hostunits) { if (item.Owner.HostKey == hostKey) { host = item.Owner; break; } } return(host.Clone()); }
public Host GetHost(int hostKey) { XElement host1; host1 = (from hos in hostingUnitsRoot.Elements() where int.Parse(hos.Element("owner").Element("hostKey").Value) == hostKey select hos).FirstOrDefault(); if (host1 == null) { throw new KeyNotFoundException("There is no host with id: " + hostKey); } List <HostingUnit> hostunits = LoadFromXML <List <HostingUnit> >(hostingUnitsPath); Host host = new Host(); foreach (var item in hostunits) { if (item.owner.hostKey == hostKey) { host = item.owner; break; } } return(host.Clone()); }