public IInterpretGateway SelectId(int id) { Collection <IInterpretGateway> kolekceGateway = new Collection <IInterpretGateway>(); XElement xelement = XElement.Load(Path); var dotaz = from phoneno in xelement.Elements("interpret") where (string)phoneno.Element("id") == id.ToString() select phoneno; foreach (XElement xEle in dotaz) { IInterpretGateway zg = new XmlInterpretGateway(); DateTime datum = DateTime.Parse(xEle.Element("datumNarozeni").Value); zg.Id = Int32.Parse(xEle.Element("id").Value); zg.Jmeno = xEle.Element("jmeno").Value; zg.UmeleckeJmeno = xEle.Element("umeleckeJmeno").Value; zg.Zeme = xEle.Element("zeme").Value; zg.DatumNarozeni = datum; kolekceGateway.Add(zg); } IInterpretGateway polozka = new XmlInterpretGateway(); if (kolekceGateway.Count == 1) { polozka = kolekceGateway[0]; } return(polozka); }
public IPisnickaGateway SelectId(int id) { Collection <IPisnickaGateway> kolekceGateway = new Collection <IPisnickaGateway>(); /* * XElement xelement = XElement.Load(Path); * var homePhone = from phoneno in xelement.Elements("pisnicka") * where (string)phoneno.Element("id") == id.ToString() * select phoneno; * foreach (XElement xEle in homePhone) * { * IPisnickaGateway zg = new XmlPisnickaGateway(); * * * * * zg.Id = Int32.Parse(xEle.Element("id").Value); * zg.Nazev = xEle.Element("nazev").Value; * zg.Delka = xEle.Element("delka").Value; * zg.Hodnoceni = float.Parse(xEle.Element("hodnoceni").Value); * * zg.Interpret.UmeleckeJmeno = xEle. * zg.Album.Nazev = xEle.Element("nazevA").Value; * zg.Nazev = xEle.Element("nazevZ").Value; * * * kolekceGateway.Add(zg); * }*/ XDocument xmlDoc = XDocument.Load(Path); var objectList = xmlDoc.Descendants("pisnicka") .Select(item => item); foreach (XElement item in objectList) { IPisnickaGateway zg = new XmlPisnickaGateway(); zg.Id = Int32.Parse(item.Element("id").Value); zg.Nazev = item.Element("nazev").Value; zg.Delka = item.Element("delka").Value; zg.Hodnoceni = float.Parse(item.Element("hodnoceni").Value); var results = item.Descendants("album").Select(result => result); foreach (XElement result in results) { IAlbumGateway ag = new XmlAlbumGateway(); ag.Nazev = result.Element("nazev").Value; zg.Album = ag; } var resultsZanr = item.Descendants("zanr").Select(result => result); foreach (XElement result in resultsZanr) { IZanrGateway zanrg = new XmlZanrGateway(); zanrg.Nazev = result.Element("nazev").Value; zg.Zanr = zanrg; } var resultsInterpret = item.Descendants("interpret").Select(result => result); foreach (XElement result in resultsInterpret) { IInterpretGateway ig = new XmlInterpretGateway(); ig.UmeleckeJmeno = result.Element("umeleckeJmeno").Value; zg.Interpret = ig; } kolekceGateway.Add(zg); } IPisnickaGateway polozka = new XmlPisnickaGateway(); if (kolekceGateway.Count == 1) { polozka = kolekceGateway[0]; } return(polozka); }