コード例 #1
0
        public async Task <Synonym> Process(Synonym synonym)
        {
            var taxon = Taxons.FirstOrDefault(t => t.Kingdom == synonym.Taxon.Kingdom &&
                                              t.Subkingdom == synonym.Taxon.Subkingdom &&
                                              t.Infrakingdom == synonym.Taxon.Infrakingdom &&
                                              t.Phylum == synonym.Taxon.Phylum &&
                                              t.Subphylum == synonym.Taxon.Subphylum &&
                                              t.Class == synonym.Taxon.Class &&
                                              t.Subclass == synonym.Taxon.Subclass &&
                                              t.Superorder == synonym.Taxon.Superorder &&
                                              t.Order == synonym.Taxon.Order &&
                                              t.Family == synonym.Taxon.Family &&
                                              t.Genus == synonym.Taxon.Genus &&
                                              t.Species == synonym.Taxon.Species &&
                                              t.Subspecies == synonym.Taxon.Subspecies &&
                                              t.Variety == synonym.Taxon.Variety &&
                                              t.Subvariety == synonym.Taxon.Subvariety &&
                                              t.Form == synonym.Taxon.Form);

            if (taxon == null)
            {
                taxon = await _taxonService.AddOrUpdateTaxonAsync(synonym.Taxon);

                Taxons.Add(taxon);
            }

            var originResult = Origins.FirstOrDefault(o => o.ParentOrigin.OriginId == Origin.OriginId &&
                                                      o.ExternalId == synonym.Origin.ExternalId &&
                                                      o.AltExternalId == synonym.Origin.AltExternalId);

            if (originResult == null)
            {
                originResult = await _originService.GetOriginAsync(Origin.OriginId, synonym.Origin.ExternalId, synonym.Origin.AltExternalId);

                Origins.Add(originResult);
            }

            if (originResult == null)
            {
                originResult = await _originService.AddOrUpdateOriginAsync(synonym.Origin, null);

                Origins.Add(originResult);
            }

            synonym.Origin = originResult;

            var synonymResult = await _synonymService.GetSynonymAsync(s => s.Name == synonym.Name &&
                                                                      s.Rank == synonym.Rank &&
                                                                      s.TaxonId == synonym.TaxonId &&
                                                                      s.OriginId == originResult.OriginId);

            if (synonymResult == null)
            {
                synonym.Origin = originResult;
                synonym.Taxon  = taxon;
                synonymResult  = await _synonymService.AddOrUpdateSynonymAsync(synonym);
            }

            return(synonymResult);
        }
コード例 #2
0
        public async Task <PlantInfo> Process(PlantInfo plantInfo)
        {
            var lifeform = Lifeforms.FirstOrDefault(l => l.ScientificName == plantInfo.ScientificName);

            if (lifeform == null)
            {
                lifeform = await _lifeformService.AddOrUpdateLifeformAsync(plantInfo.Lifeform);

                Lifeforms.Add(lifeform);
            }

            var taxon = Taxons.FirstOrDefault(t => t.Kingdom == plantInfo.Taxon.Kingdom &&
                                              t.Subkingdom == plantInfo.Taxon.Subkingdom &&
                                              t.Infrakingdom == plantInfo.Taxon.Infrakingdom &&
                                              t.Phylum == plantInfo.Taxon.Phylum &&
                                              t.Subphylum == plantInfo.Taxon.Subphylum &&
                                              t.Class == plantInfo.Taxon.Class &&
                                              t.Subclass == plantInfo.Taxon.Subclass &&
                                              t.Superorder == plantInfo.Taxon.Superorder &&
                                              t.Order == plantInfo.Taxon.Order &&
                                              t.Family == plantInfo.Taxon.Family &&
                                              t.Genus == plantInfo.Taxon.Genus &&
                                              t.Species == plantInfo.Taxon.Species &&
                                              t.Subspecies == plantInfo.Taxon.Subspecies &&
                                              t.Variety == plantInfo.Taxon.Variety &&
                                              t.Subvariety == plantInfo.Taxon.Subvariety &&
                                              t.Form == plantInfo.Taxon.Form);

            if (taxon == null)
            {
                taxon = await _taxonService.AddOrUpdateTaxonAsync(plantInfo.Taxon);

                Taxons.Add(taxon);
            }

            var originResult = Origins.FirstOrDefault(o => o.ParentOrigin.OriginId == Origin.OriginId &&
                                                      o.ExternalId == plantInfo.Origin.ExternalId &&
                                                      o.AltExternalId == plantInfo.Origin.AltExternalId);

            if (originResult == null)
            {
                originResult = await _originService.GetOriginAsync(Origin.OriginId, plantInfo.Origin.ExternalId, plantInfo.Origin.AltExternalId);

                Origins.Add(originResult);
            }

            if (originResult == null)
            {
                originResult = await _originService.AddOrUpdateOriginAsync(plantInfo.Origin, null);

                Origins.Add(originResult);
            }

            var plantInfoResult = await _plantInfoService.GetPlantInfoAsync(originResult.OriginId, taxon.TaxonId);

            if (plantInfoResult == null)
            {
                plantInfo.Origin   = originResult;
                plantInfo.Lifeform = lifeform;
                plantInfo.Taxon    = taxon;
                plantInfoResult    = await _plantInfoService.AddOrUpdatePlantInfoAsync(plantInfo);
            }

            return(plantInfoResult);
        }