Ejemplo n.º 1
0
        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);
        }
Ejemplo n.º 2
0
        public async Task <Inventory> Put(Inventory inventory)
        {
            if (inventory.OwnerId != UserId)
            {
                throw new UnauthorizedAccessException();
            }

            inventory.OwnerId ??= UserId;
            inventory.CreatedBy ??= UserId;
            inventory.ModifiedBy = UserId;
            inventory.DateCreated ??= DateTime.UtcNow;
            inventory.DateModified = DateTime.UtcNow;

            return(await _inventoryService.AddOrUpdateInventoryAsync(inventory));
        }