示例#1
0
        /// <summary>
        /// Updates a conversation time.
        /// </summary>
        /// <param name="conversation"></param>
        /// <param name="dateTime"></param>
        /// <returns></returns>
        private async Task UpdateConversationTime(string conversationId, string senderUsername, DateTime currentDateTime, DateTime dateTime)
        {
            var entity1 = await RetrieveConversationByTime(senderUsername, ConversationUtils.DateTimeToRowKey(currentDateTime));

            var entity2 = await RetrieveConversationById(senderUsername, conversationId);

            var updatedEntity = new UserConversationsTimeRowEntity
            {
                Id           = entity1.Id,
                PartitionKey = entity1.PartitionKey,
                Recipient    = entity1.Recipient,
                RowKey       = ConversationUtils.DateTimeToRowKey(dateTime)
            };

            entity2.LastModifiedUtcTime = dateTime;

            var operation1 = TableOperation.Delete(entity1);
            var operation2 = TableOperation.Replace(entity2);
            var operation3 = TableOperation.Insert(updatedEntity);

            await userConversationsTable.ExecuteBatchAsync(new TableBatchOperation
            {
                operation1, operation2, operation3
            });
        }
示例#2
0
        /// <summary>
        /// Adds 2 conversation entities for 1 participant in conversation
        /// </summary>
        /// <param name="username"></param>
        /// <param name="recipient"></param>
        /// <param name="conversation"></param>
        private async Task AddConversationForUser(string username, string recipient, Conversation conversation)
        {
            //Create Entities
            var entity1Id = new UserConversationsIdRowEntity
            {
                PartitionKey        = username,
                RowKey              = conversation.Id,
                LastModifiedUtcTime = conversation.LastModifiedDateUtc,
                Recipient           = recipient
            };

            var entity1Time = new UserConversationsTimeRowEntity
            {
                PartitionKey = username,
                RowKey       = ConversationUtils.DateTimeToRowKey(conversation.LastModifiedDateUtc),
                Recipient    = recipient,
                Id           = conversation.Id
            };

            //Define Operations
            var operation1 = TableOperation.Insert(entity1Id);
            var operation2 = TableOperation.Insert(entity1Time);

            //Define Transaction
            var transaction = new TableBatchOperation {
                operation1, operation2
            };

            //Execute Transaction
            await userConversationsTable.ExecuteBatchAsync(transaction);
        }