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 AddRequest(GuestRequest req) { if (DataSource.guestRequests.Any(item => req.GuestRequestKey == item.GuestRequestKey)) { throw new DuplicateWaitObjectException("This key already exists, DAL error"); } DataSource.guestRequests.Add(req.Clone()); DataSource_XML.saveConf(); DataSource_XML.SaveToXML(DataSource.guestRequests, guestRequestPath); }
public void AddHostingUnit(HostingUnit hostingUnit) { hostingUnit.HostingUnitKey = Configuration.HostingUnitKey++; if (DataSource.hostingUnits.Any(item => hostingUnit.HostingUnitKey == item.HostingUnitKey)) { throw new DuplicateWaitObjectException("This key already exists, DAL error"); } DataSource.hostingUnits.Add(hostingUnit.Clone()); DataSource_XML.saveConf(); DataSource_XML.SaveToXML(DataSource.hostingUnits, hostingUnitPath); }
public void DeleteHostingUnit(HostingUnit hostingUnit) { var list = (from item in DataSource.hostingUnits where hostingUnit.HostingUnitKey == item.HostingUnitKey select item).FirstOrDefault <HostingUnit>(); if (list == null) { throw new KeyNotFoundException("Key not found, DAL error"); } DataSource.hostingUnits.Remove(list); DataSource_XML.SaveToXML(DataSource.hostingUnits, hostingUnitPath); }
public void UpdateRequest(GuestRequest guestRequest) { var list = (from item in DataSource.guestRequests where guestRequest.GuestRequestKey == item.GuestRequestKey select item).FirstOrDefault <GuestRequest>(); if (list == null) { throw new KeyNotFoundException("Key not found, DAL error"); } list.Status = guestRequest.Status; DataSource_XML.SaveToXML(DataSource.guestRequests, guestRequestPath); }
public void DeleteContract(Contract c) { DataSource_XML.LoadData("Contracts"); // load the Contracts file XElement temp = ((from e in DataSource_XML.Contracts.Elements() // check if the contract exist - save it in tmp where e.Element("ChildID").Value == c.ChildID select e).FirstOrDefault()); if (temp == null) { throw new Exception("This Contract does not exist"); } temp.Remove(); DataSource_XML.SaveData("Contracts"); }
public void UpdateNanny(Nanny n) { DataSource_XML.LoadData("Nannys"); XElement temp = ((from e in DataSource_XML.Nannys.Elements() //check if the nanny exist where e.Element("ID").Value == n.ID select e).FirstOrDefault()); if (temp == null) { throw new Exception("This Nanny not exist"); } temp.ReplaceWith(DAL_Converts.NannyToXml(n)); // replace between the nanny details DataSource_XML.SaveData("Nannys"); }
public void UpdateMother(Mother m) { DataSource_XML.LoadData("Mothers"); XElement temp = ((from e in DataSource_XML.Mothers.Elements() // check if the mother exist where e.Element("ID").Value == m.ID select e).FirstOrDefault()); if (temp == null) { throw new Exception("This Mother not exist"); } temp.ReplaceWith(DAL_Converts.MotherToXml(m));// replace between the mother details DataSource_XML.SaveData("Mothers"); }
public void UpdateContract(Contract c) { DataSource_XML.LoadData("Contracts"); XElement temp = ((from e in DataSource_XML.Contracts.Elements() // check if the contract exist where e.Element("ChildID").Value == c.ChildID select e).FirstOrDefault()); if (temp == null) { throw new Exception("This Contract not exist"); } temp.ReplaceWith(DAL_Converts.ContractToXml(c)); // replace between the contract details DataSource_XML.SaveData("Contracts"); }
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); }
public void AddNanny(Nanny n) { DataSource_XML.LoadData("Nannys"); // load the nannies file XElement temp = ((from e in DataSource_XML.Nannys.Elements() // check if the Nanny already exist where e.Element("ID").Value == n.ID select e).FirstOrDefault()); if (temp != null) { throw new Exception("This Nanny already exist"); } DataSource_XML.Nannys.Add(DAL_Converts.NannyToXml(n)); DataSource_XML.SaveData("Nannys"); // save the file }
public void AddChild(Child c) { DataSource_XML.LoadData("Children"); //load the Children file XElement temp = ((from e in DataSource_XML.Children.Elements() // check if the child is exists where e.Element("ID").Value == c.ID select e).FirstOrDefault()); if (temp != null) { throw new Exception("This Child already exist"); } DataSource_XML.Children.Add(DAL_Converts.ChildToXml(c));// DataSource_XML.SaveData("Children"); }
public void AddContract(Contract c) { DataSource_XML.LoadData("Contracts"); //load the contract file XElement temp = ((from e in DataSource_XML.Contracts.Elements() // check if there is contract for this child where e.Element("ChildID").Value == c.ChildID select e).FirstOrDefault()); if (temp != null) { throw new Exception("Cannot add another Contract to same child"); } XElement contract = DAL_Converts.ContractToXml(c); contract.Element("ContractNumber").Value = (getContractNumber() + 1).ToString(); // add the new contract number DataSource_XML.Contracts.Add(contract); DataSource_XML.SaveData("Contracts"); // save the file }
public void AddMother(Mother m) { DataSource_XML.LoadData("Mothers"); // load the file if (DataSource_XML.Mothers == null) // if there isno mother that saved { DataSource_XML.Mothers.Add(DAL_Converts.MotherToXml(m)); DataSource_XML.Mothers.Save(DataSource_XML.MotherXml); } XElement temp = ((from e in DataSource_XML.Mothers.Elements()// check if the Mother already exist where e.Element("ID").Value == m.ID select e).FirstOrDefault()); if (temp != null) { throw new Exception("This Mother already exist"); } DataSource_XML.Mothers.Add(DAL_Converts.MotherToXml(m)); DataSource_XML.SaveData("Mothers"); }
internal Dal_XML_imp() { finishBankLoad = false; worker.DoWork += worker_DoWork; worker.RunWorkerAsync(); if (!File.Exists(confPath)) { DataSource_XML.saveConf(); } else { confRoot = XElement.Load(confPath); Configuration.GuestRequestKey = Int32.Parse(confRoot.Element("GuestRequestKey").Value); Configuration.HostingUnitKey = Int32.Parse(confRoot.Element("HostingUnitKey").Value); Configuration.OrderKey = Int32.Parse(confRoot.Element("OrderKey").Value); Configuration.Commission = Int32.Parse(confRoot.Element("Commission").Value); Configuration.Mail = new MailAddress(confRoot.Element("Email").Value); Configuration.Password = confRoot.Element("Password").Value; } if (!File.Exists(guestRequestPath)) { DataSource_XML.SaveToXML(new List <GuestRequest>(), guestRequestPath); } DataSource.guestRequests = DataSource_XML.LoadFromXML <List <GuestRequest> >(guestRequestPath); if (!File.Exists(hostPath)) { DataSource_XML.SaveToXML(new List <Host>(), hostPath); } DataSource.hosts = DataSource_XML.LoadFromXML <List <Host> >(hostPath); if (!File.Exists(hostingUnitPath)) { DataSource_XML.SaveToXML(new List <HostingUnit>(), hostingUnitPath); } DataSource.hostingUnits = DataSource_XML.LoadFromXML <List <HostingUnit> >(hostingUnitPath); if (!File.Exists(orderPath)) { orderRoot = new XElement("order"); orderRoot.Save(orderPath); } orderRoot = XElement.Load(orderPath); }
public void DeleteChild(Child c, bool deleteall = true) { DataSource_XML.LoadData("Children"); // load the Children file XElement temp = ((from e in DataSource_XML.Children.Elements() // check uf the child exist where e.Element("ID").Value == c.ID select e).FirstOrDefault()); if (temp == null) { throw new Exception("This Child does not exist"); } temp.Remove(); DataSource_XML.SaveData("Children"); XElement tmpC = ((from con in DataSource_XML.Contracts.Elements() // delete the contract with this child where con.Element("ChildID").Value == c.ID select con).FirstOrDefault()); if (tmpC != null && deleteall) // deleteall- if the use is to delete and not for update { DeleteContract(tmpC.XmlToContract()); } }
public void AddOrder(Order order) { var exist = (from item in orderRoot.Elements() where Int32.Parse(item.Element("OrderKey").Value) == order.OrderKey select item).Any(); if (exist) { throw new DuplicateWaitObjectException("This key already exists, DAL error"); } XElement ord = new XElement("Order"); ord.Add(new XElement("HostingUnitKey", order.HostingUnitKey), new XElement("GuestRequestKey", order.GuestRequestKey), new XElement("OrderKey", order.OrderKey), new XElement("Status", order.Status), new XElement("ImageStatus", order.ImageStatus), new XElement("CreateDate", order.CreateDate), new XElement("OrderDate", order.OrderDate)); DataSource_XML.saveConf(); orderRoot.Add(ord); orderRoot.Save(orderPath); }
public void DeleteMother(Mother m, bool deleteall = true) { DataSource_XML.LoadData("Mothers"); // load the Mothers file XElement temp = ((from e in DataSource_XML.Mothers.Elements() // check if the contract exist c where e.Element("ID").Value == m.ID select e).FirstOrDefault()); if (temp == null) { throw new Exception("This Mother does not exist"); } temp.Remove(); DataSource_XML.SaveData("Mothers"); if (deleteall) // deleteall- if the use is to delete and not for update { foreach (var item in DataSource_XML.Children.Elements()) { if (item.Element("MyMotherID").Value == m.ID) { DeleteChild(item.XmlToChild()); } } } }
public void DeleteNanny(Nanny n, bool deleteall = true) { DataSource_XML.LoadData("Nannys"); // load the nnanies file XElement temp = ((from e in DataSource_XML.Nannys.Elements() //check if the nanny exist - save it in tmp where e.Element("ID").Value == n.ID select e).FirstOrDefault()); if (temp == null) { throw new Exception("This Nanny does not exist"); } temp.Remove(); DataSource_XML.SaveData("Nannys"); if (deleteall) // deleteall- if the use is to delete and not for update { foreach (var item in DataSource_XML.Contracts.Elements()) { if (item.Element("NannyID").Value == n.ID) { DeleteContract(item.XmlToContract()); } } } }