Esempio n. 1
0
 public void Save(Player player)
 {
     string filePath = HttpContext.Current.Server.MapPath("~/App_Data/Players.xml");
     var doc = XDocument.Load(filePath);
     if (player.ID > 0)
     {
         XElement xplayer = (from p in doc.Descendants("Player")
                             where int.Parse(p.Element("ID").Value) == player.ID
                             select p).FirstOrDefault();
         if (xplayer != null)
         {
             xplayer.Element("Name").Value = player.Name;
             xplayer.Element("PlaceOfBirth").Value = player.PlaceOfBirth;
             xplayer.Element("DateOfBirth").Value = player.DateOfBirth;
         }
     }
     else
     {
         int? maxId = (from p in doc.Descendants("Player") select int.Parse(p.Element("ID").Value)).OrderByDescending(p => p).FirstOrDefault();
         int newId = maxId.HasValue ? (maxId.Value + 1) : 1;
         XElement node = new XElement("Player");
         node.Add(new XElement("ID", newId));
         node.Add(new XElement("Name", player.Name));
         node.Add(new XElement("PlaceOfBirth", player.PlaceOfBirth));
         node.Add(new XElement("DateOfBirth", player.DateOfBirth));
         doc.Root.Add(node);
     }
     doc.Save(filePath);
 }
Esempio n. 2
0
 public JsonResult Save(Player player)
 {
     new GridModel().Save(player);
     return Json(true);
 }