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);
        }
Example #2
0
        public async Task InitializeOrigin(Origin origin)
        {
            Origin = await _originService.GetOriginAsync(origin.OriginId);

            if (Origin == null)
            {
                Origin = await _originService.AddOrUpdateOriginAsync(origin, null);
            }
        }
Example #3
0
        public async Task <Origin> Get(int id)
        {
            var user = await _userService.GetIdentifyingUser(UserId);

            var origin = await _originService.GetOriginAsync(id, user);

            if (origin.User?.PhotoId != null)
            {
                var userPhoto = await _photoService.GetPhotoAsync(origin.User.PhotoId.Value);

                origin.User.PhotoThumbnailUri = userPhoto.ThumbnailUri;
            }

            return(origin);
        }