Beispiel #1
0
        public IZanrGateway SelectId(int id)
        {
            Collection <IZanrGateway> kolekceGateway = new Collection <IZanrGateway>();
            XElement xelement  = XElement.Load(Path);
            var      homePhone = from phoneno in xelement.Elements("zanr")
                                 where (string)phoneno.Element("id") == id.ToString()
                                 select phoneno;

            foreach (XElement xEle in homePhone)
            {
                IZanrGateway zg = new XmlZanrGateway();

                zg.Id    = Int32.Parse(xEle.Element("id").Value);
                zg.Nazev = xEle.Element("nazev").Value;
                zg.Popis = xEle.Element("popis").Value;



                kolekceGateway.Add(zg);
            }
            IZanrGateway polozka = new XmlZanrGateway();

            if (kolekceGateway.Count == 1)
            {
                polozka = kolekceGateway[0];
            }
            return(polozka);
        }
Beispiel #2
0
        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);
        }