public List <AddressMetaData> GetAddresses(int CustomerID)
        {
            CustomerMetaData customer = new CustomerMetaData();
            XDocument        xmlDoc   = XDocument.Load(xmlData);

            var XMLAddresses = (from item in xmlDoc.Descendants("address")
                                where item.Element("customerID").Value == CustomerID.ToString()
                                select item).ToList();

            List <AddressMetaData> lstAddresses = new List <AddressMetaData>();
            AddressMetaData        address;

            foreach (var item in XMLAddresses)
            {
                address            = new AddressMetaData();
                address.ID         = int.Parse(item.Element("ID").Value);
                address.CityID     = int.Parse(item.Element("CityID").Value);
                address.City       = GetCity(int.Parse(item.Element("CityID").Value));
                address.CustomerID = CustomerID;
                address.Title      = item.Element("Title").Value;
                address.Street     = item.Element("Street").Value;
                address.PLZ        = item.Element("PLZ").Value;
                lstAddresses.Add(address);
            }
            return(lstAddresses);
        }
        public CustomerMetaData GetCustomer(string ID)
        {
            CustomerMetaData customer = new CustomerMetaData();
            XDocument        xmlDoc   = XDocument.Load(xmlData);


            var items = (from item in xmlDoc.Descendants("customer")
                         where item.Element("ID").Value == ID
                         select item).ToList();


            foreach (XElement item in items)
            {
                customer            = new CustomerMetaData();
                customer.ID         = int.Parse(item.Element("ID").Value);
                customer.CustomerNo = item.Element("CustomerNo").Value;
                customer.FirstName  = item.Element("FirstName").Value;
                customer.LastName   = item.Element("LastName").Value;
                customer.Tel        = item.Element("Tel").Value;
                customer.Cell       = item.Element("Cell").Value;
                customer.Email      = item.Element("Email").Value;
            }



            return(customer);
        }
        public ActionResult Create(CustomerMetaData customer)
        {
            if (ModelState.IsValid)
            {
                XMLTransactions xMLTransactions = new XMLTransactions();

                xMLTransactions.AddCustomer(customer);
                return(RedirectToAction("Index"));
            }

            return(View(customer));
        }
        public ActionResult Edit(CustomerMetaData customer)
        {
            if (ModelState.IsValid)
            {
                XMLTransactions xMLTransactions = new XMLTransactions();
                xMLTransactions.EditXML(customer);

                //db.Entry(customer).State = EntityState.Modified;
                //db.SaveChanges();
                return(RedirectToAction("Index"));
            }
            return(View(customer));
        }
        // GET: Customers/Delete/5
        public ActionResult Delete(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            XMLTransactions  xMLTransactions = new XMLTransactions();
            CustomerMetaData customer        = xMLTransactions.GetCustomer(id.ToString());

            if (customer == null)
            {
                return(HttpNotFound());
            }
            return(View(customer));
        }
        public void AddCustomer(CustomerMetaData customer)
        {
            XDocument xmlDoc = XDocument.Load(xmlData);


            XElement NewCustomer = new XElement("customer");
            XElement newNode;

            newNode       = new XElement("ID");
            newNode.Value = (GetCustomers().Max(p => p.ID) + 1).ToString();
            NewCustomer.Add(newNode);

            newNode       = new XElement("CustomerNo");
            newNode.Value = customer.CustomerNo.ToString();
            NewCustomer.Add(newNode);

            newNode       = new XElement("FirstName");
            newNode.Value = customer.FirstName.ToString();
            NewCustomer.Add(newNode);


            newNode       = new XElement("LastName");
            newNode.Value = customer.LastName.ToString();
            NewCustomer.Add(newNode);

            newNode       = new XElement("Tel");
            newNode.Value = customer.Tel.ToString();
            NewCustomer.Add(newNode);

            newNode       = new XElement("Cell");
            newNode.Value = customer.Cell.ToString();
            NewCustomer.Add(newNode);

            newNode       = new XElement("Email");
            newNode.Value = customer.Email.ToString();
            NewCustomer.Add(newNode);


            xmlDoc.Root.Add(NewCustomer);


            xmlDoc.Save(xmlData);
        }
        /// <summary>
        /// Edit Customers Info
        /// </summary>
        /// <param name="customer">get an object of CustomerMetaData</param>
        public void EditXML(CustomerMetaData customer)
        {
            XDocument xmlDoc = XDocument.Load(xmlData);

            var items = (from item2 in xmlDoc.Descendants("customer")
                         where item2.Element("ID").Value == customer.ID.ToString()
                         select item2).ToList();

            foreach (XElement itemElement in items)
            {
                itemElement.SetElementValue("ID", customer.ID);
                itemElement.SetElementValue("CustomerNo", customer.CustomerNo);
                itemElement.SetElementValue("FirstName", customer.FirstName);
                itemElement.SetElementValue("LastName", customer.LastName);
                itemElement.SetElementValue("Tel", customer.Tel);
                itemElement.SetElementValue("Cell", customer.Cell);
                itemElement.SetElementValue("Email", customer.Email);
            }

            xmlDoc.Save(xmlData);
        }