public void Post([FromBody] Temperatura t) { // Carico il file XML XDocument Dati = XDocument.Load($"{_env.ContentRootPath}/{pathToDataFile}"); XElement nuovoElemento = new XElement( "Temperatura", new XAttribute("Valore", t.Valore)); Dati.Elements("root").First().Add(nuovoElemento); Dati.Save($"{_env.ContentRootPath}/{pathToDataFile}"); }
public void Put(int idx, [FromBody] Temperatura t) { try { // Carico il file XML XDocument Dati = XDocument.Load($"{_env.ContentRootPath}/{pathToDataFile}"); // prelevo quello di indice idx var elementi = Dati.Element("root").Elements("Temperatura"); var elemento = elementi.ElementAtOrDefault(idx); elemento.Attribute("Valore").Value = t.Valore.ToString(); Dati.Save($"{_env.ContentRootPath}/{pathToDataFile}"); } catch {} }