当前位置: 首页>>代码示例>>C#>>正文


C# Content.AsDictionary方法代码示例

本文整理汇总了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;
        }
开发者ID:cris-almodovar,项目名称:expando-db,代码行数:52,代码来源:DbService.cs


注:本文中的Content.AsDictionary方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。