Beispiel #1
0
        public async Task <long> ReplaceItemAsync(Item item)
        {
            if (item == null)
            {
                throw new ApiException(ApiErrorCode.MissingInformation, $"Missing parameter: ${nameof(item)}");
            }

            var retrievedItem = await GetById(item.Id.ToString());

            if (retrievedItem == null)
            {
                throw new ValidationApiException(ApiErrorCode.ItemNotFound, $"Cannot find item with id={item.Id}");
            }

            var result = await _itemsRepository.ReplaceItemAsync(item);

            var differences = _operationsRepository.GetDifferences(retrievedItem, item);
            var operation   = new Operation
            {
                Date          = DateTime.UtcNow,
                EntityId      = item.Id.ToString(),
                OperationType = OperationTypeEnum.Update.ToString(),
                Differences   = differences,
                EntityType    = EntityType
            };
            await _operationsRepository.InsertOperationsAsync(new[] { operation });

            return(result);
        }