/// <summary> /// removes a contract /// </summary> /// <param name="contract"></param> public void deleteContract(Contract contract) { XElement contractElement = (from n in DataSourceXml.Contracts.Elements() where Convert.ToInt32(n.Element("numberOfContract").Value) == contract.numberOfContract select n).FirstOrDefault(); if (contractElement != null) { contractElement.Remove(); DataSourceXml.SaveContracts(); } else { throw new Exception("the contract is not in the system.\n"); } }
/// <summary> /// updates contract info /// </summary> /// <param name="contract"></param> public void updateContract(Contract contract) { var temp = (from c in DataSourceXml.Contracts.Elements() where Convert.ToInt32(c.Element("numberOfContract").Value) == contract.numberOfContract select c).FirstOrDefault(); if (temp != null) { temp.ReplaceWith(contract.toXML()); DataSourceXml.SaveContracts(); } else { throw new Exception("the contract is not in the system.\n"); } }
/// <summary> /// adds a contract to list /// </summary> /// <param name="contract"></param> public void addContract(Contract contract) { var temp = (from c in DataSourceXml.Contracts.Elements() where Convert.ToInt32(c.Element("numberOfContract").Value) == contract.numberOfContract select c).FirstOrDefault(); if (temp == null) { DataSourceXml.Contracts.Add(contract.toXML()); DataSourceXml.SaveContracts(); } else { throw new Exception("the contract is already in the system.\n"); } }