Ejemplo n.º 1
0
        public async Task <IActionResult> BulkUpdate(
            string category,
            string collection,
            [FromBody, Required] Dictionary <string, MetadataModelContract> model,
            [FromQuery] BulkUpdateStrategy strategy = BulkUpdateStrategy.UpdateMatchedOnly)
        {
            var data = model.ToDictionary(x => x.Key, x => (x.Value.Data, x.Value.Keywords));

            switch (strategy)
            {
            case BulkUpdateStrategy.UpdateMatchedOnly:
                await _service.BulkUpsert(category, collection, data);

                break;

            case BulkUpdateStrategy.Replace:
                await _service.BulkReplace(category, collection, data);

                break;

            default:
                return(BadRequest(new { message = $"Bulk update strategy [{strategy.ToString()}] is not expected" }));
            }

            return(Ok());
        }
Ejemplo n.º 2
0
 /// <summary>
 /// Updates multiple sets of key value pairs in a given category and collection.
 /// </summary>
 /// <param name='operations'>
 /// The operations group for this extension method.
 /// </param>
 /// <param name='category'>
 /// The category
 /// </param>
 /// <param name='collection'>
 /// The collection
 /// </param>
 /// <param name='model'>
 ///  A <see cref="Dictionary{TKey, TValue}"/> containing the keys to update the metadata and keywords for
 /// </param>
 /// <param name="strategy">
 /// The bulk update strategy
 /// </param>
 /// <param name='cancellationToken'>
 /// The cancellation token.
 /// </param>
 public static async Task BulkUpdateAsync(this IMetadata operations,
                                          string category,
                                          string collection,
                                          IDictionary <string, MetadataModel> model = default,
                                          BulkUpdateStrategy strategy         = BulkUpdateStrategy.UpdateMatchedOnly,
                                          CancellationToken cancellationToken = default)
 {
     await operations.RefitClient.BulkUpdate(category, collection, model?.ToDictionary(x => x.Key,
                                                                                       x => x.Value.ToChestContract()), strategy);
 }