コード例 #1
0
 //Save person to the data file
 public void SavePerson(PersonsModel Person)
 {
     try
     {
         Person.ID = (int)(from S in PersonsData.Descendants("Item") orderby(int) S.Element("ID") descending select(int) S.Element("ID")).FirstOrDefault() + 1;
         PersonsData.Root.Add(new XElement("Item", new XElement("ID", Person.ID),
                                           new XElement("FirstName", Person.FirstName),
                                           new XElement("LastName", Person.LastName),
                                           new XElement("ContactNumber", Person.ContactNumber)));
         //Save the file with the new data
         PersonsData.Save(HttpContext.Current.Server.MapPath(this.fileName));
     }
     catch (Exception ex)
     {
         throw new Exception(ex.Message);
     }
 }
コード例 #2
0
 //Edit a persons data
 public void EditPersonsModel(PersonsModel Person)
 {
     try
     {
         //Find the person by their ID from the data source
         XElement node = PersonsData.Root.Elements("Item").Where(i => (int)i.Element("ID") == Person.ID).FirstOrDefault();
         //Update the information below
         node.SetElementValue("FirstName", Person.FirstName);
         node.SetElementValue("LastName", Person.LastName);
         node.SetElementValue("ContactNumber", Person.ContactNumber);
         //Save the file with the updated data
         PersonsData.Save(HttpContext.Current.Server.MapPath(this.fileName));
     }
     catch (Exception ex)
     {
         throw new Exception(ex.Message);
     }
 }