コード例 #1
0
        public async Task <IActionResult> Synonyms(string node, string filename)
        {
            var synonyms = await _synonymService.GetSynonymsAsync(node);

            var sb = new StringBuilder();

            foreach (var item in synonyms)
            {
                sb.AppendLine(item);
            }

            var stream = new MemoryStream(buffer: Encoding.UTF8.GetBytes(sb.ToString()));

            try
            {
                stream.Position = 0;
                return(new FileStreamResult(stream, "text/plain")
                {
                    FileDownloadName = filename
                });
            }
            catch
            {
                stream.Dispose();
                throw;
            }
        }
コード例 #2
0
        public async Task <bool> UpdateCategorySynonymsAsync(string categoryId, string userId)
        {
            // find the category document
            var categoryDocument = await CategoriesRepository.GetCategoryAsync(categoryId, userId);

            if (categoryDocument == null)
            {
                return(false);
            }

            // retrieve the synonyms
            var synonyms = await SynonymService.GetSynonymsAsync(categoryDocument.Name);

            if (synonyms == null)
            {
                return(false);
            }

            // get the document again, to reduce the likelihood of concurrency races
            categoryDocument = await CategoriesRepository.GetCategoryAsync(categoryId, userId);

            // update the document with the new name
            categoryDocument.Synonyms = synonyms;
            await CategoriesRepository.UpdateCategoryAsync(categoryDocument);

            // post a CategorySynonymsUpdatedEventData event to Event Grid
            var eventData = new CategorySynonymsUpdatedEventData
            {
                Synonyms = synonyms
            };
            var subject = $"{userId}/{categoryId}";
            await EventGridPublisher.PostEventGridEventAsync(EventTypes.Categories.CategorySynonymsUpdated, subject, eventData);

            return(true);
        }