private void FilterTaxons() { if (Taxons != null) { bool?selectedFilter = null; var prefixFilter = ""; if (TaxonFilter == "valda") { selectedFilter = true; } else if (TaxonFilter == "ejvalda") { selectedFilter = false; } else { prefixFilter = TaxonFilter; } FilteredTaxons = new ObservableCollection <TaxonItemModel>( Taxons.Where(x => (!selectedFilter.HasValue || x.Selected == selectedFilter.Value) && (string.IsNullOrEmpty(prefixFilter) || x.PrefixFilter == prefixFilter) && (string.IsNullOrEmpty(SearchText) || x.Name.IndexOf(SearchText, StringComparison.CurrentCultureIgnoreCase) != -1) )); } else { FilteredTaxons = null; } }
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); }
private void FilterTaxons() { if (Taxons != null) { FilteredTaxons = new List <Taxon>( Taxons.Where(x => (string.IsNullOrEmpty(TaxonFilter) || x.Type == TaxonFilter) && (string.IsNullOrEmpty(SearchText) || x.Name.IndexOf(SearchText, StringComparison.CurrentCultureIgnoreCase) != -1) )); } else { FilteredTaxons = null; } }
public ActionResult EditReview(int id) { IReviewRepository reviews = new ReviewRepository(); IGenericRepository generics = new GenericRepository(); ITaxonRepository taxons = new TaxonRepository(); TblReview review = reviews.getSingleReviewEdit(id); ViewData["addphase"] = new SelectList(generics.getAllPhase(), "ID", "PhaseDesc", review.PhaseID); ViewData["committee"] = new SelectList(generics.getAllCommittees(), "ID", "Description", review.CommitteeID); int animal = generics.getExternalRef(UpdateUtils.ANIMALS, UpdateUtils.TYPE_KINGDOM); int kingdom = (int)review.KingdomID; IList <AGeneralTaxon> lists_countries, lists_genus, lists_species = null; int SpeciesID = review.TaxonID.GetValueOrDefault(); Taxons genus = taxons.getTaxonbySpecies(SpeciesID, (int)review.KingdomID); if (review.KingdomID == animal) { lists_countries = taxons.getCountries(SpeciesID, UpdateUtils.SPECIES, UpdateUtils.ANIMALS); lists_genus = taxons.getAGenus(); lists_species = taxons.getASpeciesbyGenus(genus.genrecid); } else { lists_countries = taxons.getCountries(SpeciesID, UpdateUtils.SPECIES, UpdateUtils.PLANTS); lists_genus = taxons.getPGenus(); lists_species = taxons.getPSpeciesbyGenus(genus.genrecid); } ViewData["animal"] = animal; ViewData["kingdom"] = kingdom; ViewData["countries"] = new SelectList(lists_countries, "RecID", "TaxonName", review.CountryID); ViewData["genus"] = new SelectList(lists_genus, "RecID", "TaxonName", genus.genrecid); ViewData["species"] = new SelectList(lists_species, "RecID", "TaxonName", SpeciesID); return(View()); }
public async Task <IEnumerable <Synonym> > Process(IEnumerable <Synonym> synonyms) { var synonymResults = new List <Synonym>(); var newOrigins = new List <Origin>(); var newSynonyms = new List <Synonym>(); foreach (var synonym in synonyms) { 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); } synonym.Taxon = taxon; // Do we already have the same origin in our insert list? var originResult = newOrigins.FirstOrDefault(o => o.ParentOrigin.OriginId == Origin.OriginId && o.ExternalId == synonym.Origin.ExternalId && o.AltExternalId == synonym.Origin.AltExternalId); if (originResult == null) { // See if it already exists, if not, add it to the insert list originResult = await _originService.GetOriginAsync(Origin.OriginId, synonym.Origin.ExternalId, synonym.Origin.AltExternalId); if (originResult == null) { newOrigins.Add(synonym.Origin); } else { Origins.Add(originResult); } } } if (newOrigins.Any()) { newOrigins = (await _originService.AddOriginsAsync(newOrigins)).ToList(); Origins.AddRange(newOrigins); } foreach (var synonym in synonyms) { var origin = Origins.FirstOrDefault(o => o.ParentOrigin.OriginId == Origin.OriginId && o.ExternalId == synonym.Origin.ExternalId && o.AltExternalId == synonym.Origin.AltExternalId); if (origin == null) { origin = await _originService.GetOriginAsync(Origin.OriginId, synonym.Origin.ExternalId, synonym.Origin.AltExternalId); } synonym.Origin = origin; var synonymResult = await _synonymService.GetSynonymAsync(s => s.Name == synonym.Name && s.Rank == synonym.Rank && s.TaxonId == synonym.TaxonId && s.OriginId == synonym.Origin.OriginId); if (synonymResult == null) { newSynonyms.Add(synonym); } } if (newSynonyms.Any()) { newSynonyms = (await _synonymService.AddSynonymsAsync(newSynonyms)).ToList(); } foreach (var newSynonym in newSynonyms) { var synonym = synonyms.First(s => s.Origin.OriginId == newSynonym.Origin.OriginId && s.Taxon.TaxonId == newSynonym.Taxon.TaxonId); newSynonym.Origin = Origins.FirstOrDefault(o => o.OriginId == newSynonym.Origin.OriginId); newSynonym.Taxon = Taxons.FirstOrDefault(t => t.TaxonId == newSynonym.Taxon.TaxonId); } return(newSynonyms); }
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); }
public async Task <IEnumerable <PlantInfo> > Process(IEnumerable <PlantInfo> plantInfos) { var newOrigins = new List <Origin>(); var newPlantInfos = new List <PlantInfo>(); foreach (var plantInfo in plantInfos) { var lifeform = Lifeforms.FirstOrDefault(l => l.ScientificName == plantInfo.ScientificName); if (lifeform == null) { lifeform = await _lifeformService.AddOrUpdateLifeformAsync(plantInfo.Lifeform); Lifeforms.Add(lifeform); } plantInfo.Lifeform = 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.Kingdom != plantInfo.Taxon.Kingdom || taxon.Family != plantInfo.Taxon.Family) { taxon = await _taxonService.AddOrUpdateTaxonAsync(plantInfo.Taxon); Taxons.Add(taxon); } plantInfo.Taxon = taxon; // Do we already have the same origin in our insert list? var originResult = newOrigins.FirstOrDefault(o => o.ParentOrigin.OriginId == Origin.OriginId && o.ExternalId == plantInfo.Origin.ExternalId && o.AltExternalId == plantInfo.Origin.AltExternalId); if (originResult == null) { // See if it already exists, if not, add it to the insert list originResult = await _originService.GetOriginAsync(Origin.OriginId, plantInfo.Origin.ExternalId, plantInfo.Origin.AltExternalId); if (originResult == null) { newOrigins.Add(plantInfo.Origin); } else { Origins.Add(originResult); } } } if (newOrigins.Any()) { newOrigins = (await _originService.AddOriginsAsync(newOrigins)).ToList(); Origins.AddRange(newOrigins); } var distinctPlantInfos = plantInfos.DistinctBy(p => new { p.Taxon.Genus, p.Taxon.Species, p.Taxon.Subspecies, p.Taxon.Variety, p.Taxon.Subvariety, p.Taxon.Form }); foreach (var plantInfo in distinctPlantInfos) { var origin = Origins.FirstOrDefault(o => o.ExternalId == plantInfo.Origin.ExternalId && o.AltExternalId == plantInfo.Origin.AltExternalId); if (origin == null) { origin = await _originService.GetOriginAsync(Origin.OriginId, plantInfo.Origin.ExternalId, plantInfo.Origin.AltExternalId); } plantInfo.Origin = origin; var plantInfoResult = await _plantInfoService.GetPlantInfoAsync(plantInfo.Origin.OriginId, plantInfo.Taxon.TaxonId); if (plantInfoResult == null) { newPlantInfos.Add(plantInfo); } } if (newPlantInfos.Any()) { newPlantInfos = (await _plantInfoService.AddPlantInfosAsync(newPlantInfos)).ToList(); } foreach (var newPlantInfo in newPlantInfos) { var plantInfo = plantInfos.First(p => p.Origin.OriginId == newPlantInfo.Origin.OriginId && p.Taxon.TaxonId == newPlantInfo.Taxon.TaxonId); plantInfo.PlantInfoId = newPlantInfo.PlantInfoId; newPlantInfo.Taxon = plantInfo.Taxon; newPlantInfo.Origin = plantInfo.Origin; newPlantInfo.Lifeform = plantInfo.Lifeform; } var plantInfoLocations = plantInfos.Where(p => p.Locations != null && p.Locations.Any()) .SelectMany(p => p.Locations) .DistinctBy(pl => new { pl.PlantInfo.PlantInfoId, pl.Location.LocationId }) .ToList(); if (plantInfoLocations.Any() && newPlantInfos.Any()) { var regions = plantInfos.SelectMany(p => p.Locations).Select(l => l.Location.Region).Distinct(); var countries = plantInfos.SelectMany(p => p.Locations).Select(l => l.Location.Country).Distinct(); var locations = (await _locationService.GetLocationsAsync(l => countries.Contains(l.Country) || regions.Contains(l.Region))).ToList(); var missingLocations = plantInfoLocations.GroupJoin(locations, pl => new { pl.Location.Region, pl.Location.Country }, l => new { l.Region, l.Country }, (pl, l) => pl.Location) .DistinctBy(l => new { l.Region, l.Country }) .ToList(); if (missingLocations.Any()) { var locationResult = await _locationService.AddLocationsAsync(missingLocations); locations.AddRange(locationResult.ToList()); } var plantLocationsToAdd = new List <PlantLocation>(); foreach (var plantInfoLocation in plantInfoLocations) { var newPlantInfo = newPlantInfos.FirstOrDefault(npl => npl.Origin.OriginId == plantInfoLocation.PlantInfo.Origin.OriginId && npl.Taxon.TaxonId == plantInfoLocation.PlantInfo.Taxon.TaxonId); if (newPlantInfo != null) { var location = locations.First(l => l.Country == plantInfoLocation.Location.Country && l.Region == plantInfoLocation.Location.Region); plantLocationsToAdd.Add(new PlantLocation { PlantInfo = newPlantInfo, Location = location, Status = plantInfoLocation.Status }); } } if (plantInfoLocations.Any()) { var plantLocationsResult = (await _plantInfoService.AddPlantLocations(plantLocationsToAdd)).ToList(); foreach (var newPlantInfo in newPlantInfos) { var newPlantInfoLocations = plantLocationsResult.Where(pl => pl.PlantInfo.PlantInfoId == newPlantInfo.PlantInfoId); newPlantInfo.Locations = newPlantInfoLocations.Any() ? newPlantInfoLocations : null; } } } return(newPlantInfos); }