public static Konta WczytajKonta(string filePath) { try { XDocument xml = XDocument.Load(filePath); IEnumerable <KontoModel> dane = from konto in xml.Root.Descendants("Konto") select new KontoModel ( konto.Element("AdresSerwera").Value, konto.Element("Port").Value, konto.Element("ImieNazwisko").Value, konto.Element("AdresEmail").Value, konto.Element("Haslo").Value); Konta konta = new Konta(); foreach (KontoModel konto in dane) { konta.DodajKonto(konto); } return(konta); } catch (Exception exc) { throw new Exception("Błąd przy odczycie", exc); } }
public static void ZapiszKonta(string filePath, Konta konta) { try { XDocument xml = new XDocument(new XDeclaration("1.0", "utf-8", "yes"), new XElement("Konta", from KontoModel konto in konta select new XElement("Konto", new XElement("AdresSerwera", konto.AdresSerwera), new XElement("Port", konto.Port), new XElement("ImieNazwisko", konto.ImieNazwisko), new XElement("AdresEmail", konto.AdresEmail), new XElement("Haslo", konto.Haslo)))); xml.Save(filePath); } catch (Exception exc) { throw new Exception("Błąd przy zapisie", exc); } }