Exemple #1
0
        public async Task <string> AddTextNoteAsync(string text, string userId, string categoryId)
        {
            if (text.ToLower().Contains("protiviti"))
            {
                text = $"{text} - Face the Future with Fear!";
            }

            // create the document in Cosmos DB
            var textDocument = new TextDocument
            {
                UserId     = userId,
                Text       = text,
                CategoryId = categoryId
            };
            var textId = await TextRepository.AddTextNoteAsync(textDocument);

            // post a TextCreated event to Event Grid
            var eventData = new TextCreatedEventData
            {
                Preview  = text.Truncate(MaximumTextPreviewLength),
                Category = categoryId
            };
            var subject = $"{userId}/{textId}";
            await EventGridPublisher.PostEventGridEventAsync(EventTypes.Text.TextCreated, subject, eventData);

            return(textId);
        }