Beispiel #1
0
        public async Task InitializeOrigin(Origin origin)
        {
            Origin = await _originService.GetOriginAsync(origin.OriginId);

            if (Origin == null)
            {
                Origin = await _originService.AddOrUpdateOriginAsync(origin, 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);
        }
Beispiel #3
0
        public async Task <PlantInfo> Put(PlantInfo plantInfo)
        {
            plantInfo.CreatedBy = UserId;
            var userId = await _userService.GetUserIdAsync(UserId);

            plantInfo.UserId = userId;

            if (plantInfo.Origin != null && plantInfo.Origin.OriginId == 0)
            {
                plantInfo.Origin.UserId = userId;
                plantInfo.Origin        = await _originService.AddOrUpdateOriginAsync(plantInfo.Origin, UserId);
            }

            var plantInfoResult = await _plantInfoService.AddOrUpdatePlantInfoAsync(plantInfo);

            if (plantInfo.Photos != null && plantInfo.Photos.Any())
            {
                foreach (var photo in plantInfo.Photos)
                {
                    photo.TypeId = plantInfoResult.PlantInfoId;
                }

                plantInfoResult.Photos = await _photoService.AddOrUpdatePhotosAsync(plantInfo.Photos);
            }

            return(plantInfoResult);
        }
Beispiel #4
0
        public async Task <Data.Shared.Models.InventoryItem> AddOrUpdateInventoryItemAsync(Data.Shared.Models.InventoryItem inventoryItem, string userId)
        {
            inventoryItem.DateModified = DateTime.UtcNow;

            if (inventoryItem.Origin != null && inventoryItem.Origin.OriginId == 0 && !string.IsNullOrEmpty(inventoryItem.Origin.Name))
            {
                inventoryItem.Origin = await _originService.AddOrUpdateOriginAsync(inventoryItem.Origin, userId);
            }

            var result = await _inventoryItemRepository.AddOrUpdateAsync(i => i.Id == inventoryItem.InventoryItemId, inventoryItem.AsStore());

            return(result.AsModel());
        }
        public async Task <Specimen> Put(Specimen specimen)
        {
            specimen.CreatedBy = UserId;

            if (specimen.InventoryItem == null)
            {
                specimen.InventoryItem = new InventoryItem {
                    CreatedBy = UserId
                };
            }

            specimen.InventoryItem.CreatedBy = UserId;
            var userId = await _userService.GetUserIdAsync(UserId);

            specimen.InventoryItem.UserId = userId;

            if (specimen.InventoryItem.Origin != null && specimen.InventoryItem.Origin.OriginId == 0)
            {
                specimen.InventoryItem.Origin.UserId = userId;
                specimen.InventoryItem.Origin        = await _originService.AddOrUpdateOriginAsync(specimen.InventoryItem.Origin, UserId);
            }

            if (specimen.InventoryItem.Inventory == null || specimen.InventoryItem.Inventory.InventoryId == 0)
            {
                var inventory = await _inventoryService.GetInventoryAsync(UserId);

                if (inventory == null)
                {
                    inventory = await _inventoryService.AddOrUpdateInventoryAsync(new Inventory { OwnerId = UserId, CreatedBy = UserId, DateCreated = DateTime.Now });
                }
                specimen.InventoryItem.Inventory = inventory;
            }

            specimen.InventoryItem = await _inventoryService.AddOrUpdateInventoryItemAsync(specimen.InventoryItem, UserId);

            var specimenResult = await _specimenService.AddOrUpdateAsync(specimen, UserId);

            if (specimen.Photos != null && specimen.Photos.Any())
            {
                foreach (var photo in specimen.Photos)
                {
                    photo.TypeId = specimenResult.SpecimenId;
                }

                specimenResult.Photos = await _photoService.AddOrUpdatePhotosAsync(specimen.Photos);
            }

            return(specimenResult);
        }
Beispiel #6
0
        public async Task <Origin> Put(Origin origin)
        {
            origin.UserId = await _userService.GetUserIdAsync(UserId);

            return(await _originService.AddOrUpdateOriginAsync(origin, UserId));
        }