Esempio n. 1
0
 public static void SaveKingdom(Kingdom kingdom)
 {
     using (var db = new FloraModel())
     {
         db.Kingdoms.AddOrUpdate(kingdom);
         db.SaveChanges();
     }
 }
Esempio n. 2
0
        private static SpeciesSelected FillFlore(RootObject root)
        {
            var flore = new SpeciesSelected();

            var content = root.query.pages[0].revisions[0].content;
            var source  = content;

            source = WebUtility.HtmlDecode(source);
            var resultat = new HtmlDocument();

            resultat.LoadHtml(source);

            var toftitle = resultat.DocumentNode.Descendants().Where
                               (x => (x.Name == "div" && x.Attributes["class"] != null &&
                                      x.Attributes["class"].Value.Contains("entete"))).ToList();

            flore.Species = new Species();
            flore.Species.BinomialName = toftitle[0].Descendants("i").ToList()[0].InnerText;

            toftitle = resultat.DocumentNode.Descendants().Where
                           (x => (x.Name == "div" && x.Attributes["class"] != null &&
                                  x.Attributes["class"].Value.Contains("images"))).ToList();

            var urlPhoto = toftitle[0].Descendants("img").ToList()[0].Attributes["src"].Value;

            flore.Photo     = new Photo();
            flore.Photo.Url = "https:" + urlPhoto;

            toftitle = resultat.DocumentNode.Descendants().Where
                           (x => (x.Name == "table" && x.Attributes["class"] != null &&
                                  x.Attributes["class"].Value.Contains("taxobox_classification"))).ToList();

            //var table = toftitle[0].Descendants("tbody").ToList()[0];

            foreach (var item in toftitle[0].Descendants("tr"))
            {
                var a = item.Descendants("a").ToList()[0].InnerText;
                switch (a)
                {
                case "Règne":
                    flore.Kingdom = new Kingdom();
                    var kname = item.Descendants("a").ToList()[1].InnerText;
                    flore.Kingdom = !Kingdom.IsExist(kname) ? Kingdom.GetKingdom(kname) : Kingdom.GetKingdom(kname);
                    break;

                case "Division":
                    flore.Phylum = new Phylum();
                    var pname = item.Descendants("a").ToList()[1].InnerText;
                    flore.Phylum = !Phylum.IsExist(pname) ? new Phylum {
                        Name = pname
                    } : Phylum.GetPhylum(pname);
                    break;

                case "Classe":
                    flore.Classe = new Classe();
                    var cname = item.Descendants("a").ToList()[1].InnerText;
                    flore.Classe = !Classe.IsExist(cname) ? new Classe {
                        Name = cname
                    } : Classe.GetClasse(cname);
                    break;

                case "Ordre":
                    flore.Order = new Order();
                    var oname = item.Descendants("a").ToList()[1].InnerText;
                    flore.Order = !Order.IsExist(oname) ? new Order {
                        Name = oname
                    } : Order.GetOrder(oname);
                    break;

                case "Famille":
                    flore.Family = new Family();
                    var fname = item.Descendants("a").ToList()[1].InnerText;
                    flore.Family = !Family.IsExist(fname) ? new Family {
                        Name = fname
                    } : Family.GetFamily(fname);
                    break;

                case "Genre":
                    flore.Genus = new Genus();
                    var gname = item.Descendants("a").ToList()[1].InnerText;
                    flore.Genus = !Genus.IsExist(gname) ? new Genus {
                        Name = gname
                    } : Genus.GetGenus(gname);
                    break;

                default:
                    break;
                }
            }
            flore.Species.Photos = new List <Photo> {
                flore.Photo
            };
            flore.Genus.Specieses = new List <Species> {
                flore.Species
            };
            flore.Family.Genera = new List <Genus> {
                flore.Genus
            };
            flore.Order.Families = new List <Family> {
                flore.Family
            };
            flore.Classe.Orders = new List <Order> {
                flore.Order
            };
            flore.Phylum.Classes = new List <Classe> {
                flore.Classe
            };
            flore.Kingdom.Phylums = new List <Phylum> {
                flore.Phylum
            };
            return(flore);
        }