/// <summary>
        /// Executes the operation on the offline store.
        /// </summary>
        /// <param name="store">The offline store.</param>
        /// <param name="item">The item to use for the store operation.</param>
        /// <returns>A task that completes when the store operation is completed.</returns>
        public override async Task ExecuteOperationOnOfflineStoreAsync(IOfflineStore store, JObject item, CancellationToken cancellationToken = default)
        {
            var existingItem = await store.GetItemAsync(TableName, ItemId, cancellationToken).ConfigureAwait(false);

            if (existingItem != null)
            {
                throw new OfflineStoreException("Insert failed - the item already exists in the offline store");
            }
            await store.UpsertAsync(TableName, new[] { item }, false, cancellationToken).ConfigureAwait(false);
        }
Пример #2
0
        /// <summary>
        /// Executes the operation on the offline store.
        /// </summary>
        /// <param name="store">The offline store.</param>
        /// <param name="item">The item to use for the store operation.</param>
        /// <returns>A task that completes when the store operation is completed.</returns>
        public override async Task ExecuteOperationOnOfflineStoreAsync(IOfflineStore store, JObject item, CancellationToken cancellationToken = default)
        {
            var itemId       = ServiceSerializer.GetId(item);
            var originalItem = await store.GetItemAsync(TableName, itemId, cancellationToken).ConfigureAwait(false);

            if (originalItem == null)
            {
                throw new OfflineStoreException($"Item with ID '{itemId}' does not exist in the offline store.");
            }
            await store.UpsertAsync(TableName, new[] { item }, false, cancellationToken).ConfigureAwait(false);
        }