public void EditTraining(Training training)
        {
            XElement node = trainingData.Root.Elements("item").Where(i => (int)i.Element("id") == training.ID).FirstOrDefault();

            node.SetElementValue("name", training.Name);
            node.SetElementValue("instructor", training.Instructor);
            node.SetElementValue("startDate", training.StartDate.ToShortDateString());
            node.SetElementValue("endDate", training.EndDate.ToShortDateString());
            node.SetElementValue("time", training.Time);
            node.SetElementValue("duration", training.Duration);

            trainingData.Save(HttpContext.Current.Server.MapPath("~/App_Data/Trainings.xml"));
        }
        public void InsertTraining(Training training)
        {
            //Descendants method is used to get a collection of a particular child elements from a XML file.

            training.ID = (int)(from b in trainingData.Descendants("item") orderby (int)b.Element("id") descending select (int)b.Element("id")).FirstOrDefault() + 1;

            trainingData.Root.Add(new XElement("item", new XElement("id", training.ID),
                new XElement("name", training.Name),
                new XElement("instructor", training.Instructor),
                new XElement("startDate", training.StartDate.Date.ToShortDateString()),
                new XElement("endDate", training.EndDate.Date.ToShortDateString()),
                new XElement("time", training.Time),
                new XElement("duration", training.Duration) ));

            trainingData.Save(HttpContext.Current.Server.MapPath("~/App_Data/Trainings.xml"));
        }
 public void Edit(Training training)
 {
     _trainingRepository.EditTraining(training);
 }
 public void Create(Training training)
 {
     _trainingRepository.InsertTraining(training);
 }