Exemplo n.º 1
0
        public void AddMother(Mother mother)
        {
            // Searching for the mother ID in the mother's XML file (returns 0 if not found)
            int temp = (from n in DataSourceXml.Mothers.Elements()
                        where int.Parse(n.Element("Id").Value) == mother.Id
                        select int.Parse(n.Element("Id").Value)).FirstOrDefault();

            if (temp != 0)
            {
                throw new Exception("ERROR: The mother with id: " + mother.Id + " already exist in the database !!!");
            }
            else
            {
                DataSourceXml.Mothers.Add(mother.toXML());
                DataSourceXml.SaveInMothers();
            }
        }
Exemplo n.º 2
0
        public void RemoveMother(int motherId)
        {
            // Searching for the mother instance in the mother's XML file (returns null if not found)
            XElement motherToRemove = (from n in DataSourceXml.Mothers.Elements()
                                       where int.Parse(n.Element("Id").Value) == motherId
                                       select n).FirstOrDefault();

            if (motherToRemove == null)
            {
                throw new Exception("ERROR: The mother with id: " + motherId + " not exist in the database !!!");
            }
            else
            {
                motherToRemove.Remove();
                DataSourceXml.SaveInMothers();
            }
        }