本文整理汇总了C#中Content.AsDictionary方法的典型用法代码示例。如果您正苦于以下问题:C# Content.AsDictionary方法的具体用法?C# Content.AsDictionary怎么用?C# Content.AsDictionary使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Content
的用法示例。
在下文中一共展示了Content.AsDictionary方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: OnPatchContentAsync
private async Task<object> OnPatchContentAsync(dynamic req, CancellationToken token)
{
var stopwatch = new Stopwatch();
stopwatch.Start();
var collectionName = (string)req["collection"];
if (String.IsNullOrWhiteSpace(collectionName))
throw new ArgumentException("collection cannot be null or blank");
if (!_db.ContainsCollection(collectionName))
return HttpStatusCode.NotFound;
var guid = (Guid)req["id"];
if (guid == Guid.Empty)
throw new ArgumentException("id cannot be Guid.Empty");
var excludedFields = new[] { "collection", "id" };
var dictionary = this.Bind<DynamicDictionary>(excludedFields).ToDictionary();
if (dictionary == null || dictionary.Count == 0)
throw new InvalidOperationException("There is no data for this operation");
var contentPatch = new Content(dictionary);
var collection = _db[collectionName];
var count = collection.Count(new SearchCriteria { Query = "_id:" + guid.ToString() });
if (count == 0)
return HttpStatusCode.NotFound;
var content = await collection.GetAsync(guid);
if (content == null)
return HttpStatusCode.NotFound;
var patchDictionary = contentPatch.AsDictionary();
var contentDictionary = content.AsDictionary();
var keysToUpdate = patchDictionary.Keys.Except(new[] { "collection", Content.ID_FIELD_NAME, Content.CREATED_TIMESTAMP_FIELD_NAME, Content.MODIFIED_TIMESTAMP_FIELD_NAME });
foreach (var key in keysToUpdate)
contentDictionary[key] = patchDictionary[key];
var affected = await collection.UpdateAsync(content);
stopwatch.Stop();
var responseDto = new UpdateResponseDto
{
elapsed = stopwatch.Elapsed.ToString(),
fromCollection = collectionName,
affectedCount = affected
};
return responseDto;
}