예제 #1
0
        /// <summary>
        /// Update Root for specific chat profile
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="collection"></param>
        /// <param name="botId"></param>
        /// <param name="rootId"></param>
        /// <param name="profile"></param>
        /// <returns></returns>
        public static async Task <bool> SetRootNodeById <T>(this IMongoCollection <T> collection, string botId, string rootId, string profile = BotChatProfile.DefaultProfile) where T : BotModel
        {
            var node = await collection.GetChatProfileById(botId, profile);

            if (node == null)
            {
                node = new BotChatProfile {
                    Name = profile
                };
                await collection.AddOrUpdateChatProfileById(botId, node);
            }
            var result = await collection.UpdateOneAsync(item => item._id == botId && item.Configuration.ChatProfiles.Any(val => val.Name == profile),
                                                         Builders <T> .Update.Set(x => x.Configuration.ChatProfiles[-1].Root, rootId));

            return(result.ModifiedCount > 0);
        }