예제 #1
0
        public Task <Tag> PatchAsync(TagPatchInfo patchInfo, CancellationToken cancellationToken)
        {
            if (patchInfo == null)
            {
                throw new ArgumentNullException(nameof(patchInfo));
            }

            cancellationToken.ThrowIfCancellationRequested();
            var tag = tags.Find(item => item.Id == patchInfo.Id).FirstOrDefault();

            if (tag == null)
            {
                throw new TagNotFoundException(patchInfo.Id);
            }

            var updated = false;

            if (patchInfo.Name != null)
            {
                tag.Name = patchInfo.Name;
                updated  = true;
            }

            if (updated)
            {
                tags.ReplaceOne(item => item.Id == patchInfo.Id, tag);
            }

            return(Task.FromResult(tag));
        }
예제 #2
0
        public Task <Tag> PatchAsync(TagPatchInfo patchInfo, CancellationToken cancellationToken)
        {
            if (patchInfo == null)
            {
                throw new ArgumentNullException(nameof(patchInfo));
            }

            cancellationToken.ThrowIfCancellationRequested();
            var tag = tags.Find(item => item.Id == patchInfo.Id).FirstOrDefault();

            if (tag == null)
            {
                throw new TagNotFoundException(patchInfo.Id);
            }

            if (string.IsNullOrEmpty(patchInfo.Name))
            {
                return(Task.FromResult(tag));
            }

            tag.Name = patchInfo.Name;
            tags.ReplaceOne(item => item.Id == patchInfo.Id, tag);
            return(Task.FromResult(tag));
        }