private async Task AddUserTeamMembershipAsync(string teamId, ChannelAccount member)
        {
            var userMembership = new UserTeamMembership
            {
                TeamId      = teamId,
                UserTeamsId = member.Id,
            };

            await this.userManagementHelper.AddUserTeamMembershipAsync(userMembership);
        }
示例#2
0
        // Process the new member added to the team
        // This means recording the team membership, user information, and sending the user a welcome card
        private async Task ProcessNewTeamMemberAsync(TeamsChannelAccount member, Team teamInfo, Attachment welcomeCard)
        {
            this.logProvider.LogInfo($"Processing member {member.Id} in team {teamInfo.Id}");

            try
            {
                var attachments = new List <Attachment> {
                    welcomeCard
                };
                var aadObjectId = (member.ObjectId ?? member.Properties["aadObjectId"]).ToString();

                // Record the user's membership in the team
                this.logProvider.LogInfo($"Recording team membership");
                var userTeamMembership = new UserTeamMembership
                {
                    TeamId      = teamInfo.Id,
                    UserTeamsId = member.Id,
                };
                await this.userManagementHelper.AddUserTeamMembershipAsync(userTeamMembership);

                // See if the user has events to share
                var events = await this.eventDataProvider.GetEventsByOwnerObjectIdAsync(aadObjectId);

                if (events.Count > 0)
                {
                    this.logProvider.LogInfo($"User has {events.Count} existing events, will send invitation to share");
                    attachments.Add(CelebrationCard.GetShareEventAttachment(teamInfo.Id, teamInfo.Name, aadObjectId));
                }

                // Get the user record
                var userInfo = await this.userManagementHelper.GetUserByAadObjectIdAsync(aadObjectId);

                // Create conversation if needed
                var conversationId = userInfo?.ConversationId;
                if (conversationId == null)
                {
                    conversationId = await this.connectorClient.Conversations.CreateOrGetDirectConversationAsync(teamInfo.TenantId, member.Id);
                }

                // Send the personal welcome message
                this.logProvider.LogInfo($"Sending personal welcome message");
                await this.connectorClient.Conversations.SendCardListAsync(conversationId, attachments);

                this.logProvider.LogInfo("Saving member details");
                await this.StoreUserDetailsIfNeededAsync(member, teamInfo, conversationId);
            }
            catch (Exception ex)
            {
                this.logProvider.LogError($"Failed to process new member {member.Id} in {teamInfo.Id}", ex);
                throw;
            }
        }
        /// <summary>
        /// Add record in UserTeamMembership collection.
        /// </summary>
        /// <param name="userTeamMembership">UserTeamMembership object</param>
        /// <returns>A <see cref="Task"/> representing the asynchronous operation.</returns>
        public async Task AddUserTeamMembershipAsync(UserTeamMembership userTeamMembership)
        {
            await this.EnsureInitializedAsync();

            await this.documentClient.CreateDocumentAsync(this.userTeamMembershipCollection.SelfLink, userTeamMembership);
        }