Exemplo n.º 1
0
        /// <summary>
        /// dalete contract from the data base
        /// </summary>
        /// <param name="ContractNumber">contract number to remove</param>
        public void removeContract(int ContractNumber)
        {
            XElement result = (from contract in DataSourceXml.ContractRoot.Elements()
                               where Convert.ToInt32(contract.Element("ContractNumber").Value) == ContractNumber
                               select contract).FirstOrDefault();

            if (result != null)
            {
                result.Remove();
                DataSourceXml.saveContracts();
            }
            else
            {
                throw new DALException("ERROR: There is no contract with this number to remove");
            }
        }
Exemplo n.º 2
0
        /// <summary>
        /// delete nanny from the collection
        /// </summary>
        /// <param name="id">id number of the nanny</param>
        public void removeNanny(int id)
        {
            XElement result = (from nanny in DataSourceXml.NannyRoot.Elements()
                               where Convert.ToInt32(nanny.Element("Id").Value) == id
                               select nanny).FirstOrDefault();

            if (result != null)
            {
                result.Remove();
                DataSourceXml.saveContracts();
            }
            else
            {
                throw new DALException("ERROR: There is no nanny with this id to remove");
            }
        }
Exemplo n.º 3
0
        //--------------menage contracts----------------//

        /// <summary>
        /// adds a contract to the data base
        /// Exception:
        /// there are a contract for this child
        /// in the data base no are a mother or nanny with approprite ID
        /// </summary>
        /// <param name="con">object of contract to add</param>
        public void addContract(Contract con)
        {
            if (DataSourceXml.ContractRoot.Elements().Any(x => (Convert.ToInt32(x.Element("ChildId").Value) == con.ChildId)))
            {
                throw new DALException("There is the same contract with this child id already");
            }
            if (DataSourceXml.NannyRoot.Elements().All(x => (Convert.ToInt32(x.Element("Id").Value) != con.NannyId)))
            {
                throw new DALException("ERROR: There is no are a nanny  with this id");
            }
            if (DataSourceXml.MotherRoot.Elements().All(x => (Convert.ToInt32(x.Element("Id").Value) != con.MotherId)))
            {
                throw new DALException("ERROR: There is no are a Mother with this id");
            }
            //con.ContractNumber = ++Range;

            DataSourceXml.ContractRoot.Add(con.Clone().ContantToXML());
            DataSourceXml.saveContracts();
        }