public async Task <bool> CreateContextWithResponsesAsync(ContextWrapper context, IEnumerable <BotResponse> responses) { try { context.InitNewContext(context.ExpressionRawStr, _parser, _dict, shouldWorkWithTermsForms: true, tokenFormsMaxNumberForAsterix: 30); _chatBotContext.Contexts.Add(context); await _chatBotContext.SaveChangesAsync(); _projectsContexts[context.ProjectId].Add(context); for (int i = 0; i < responses.Count(); i++) { responses.ElementAt(i).Pattern = context; responses.ElementAt(i).PatternId = context.Id; _chatBotContext.BotResponses.Add(responses.ElementAt(i)); _contextsResponses[responses.ElementAt(i).PatternId].Add(responses.ElementAt(i)); } await _chatBotContext.SaveChangesAsync(); _logger.LogInformation("Contexts with responses added ({context.Id})", context.Id); return(true); } catch (Exception ex) { _logger.LogError(ex, "can't add context with responses"); return(false); } }
public async Task <bool> AddContextAsync(ContextWrapper context) { try { context.InitNewContext(context.ExpressionRawStr, _parser, _dict, shouldWorkWithTermsForms: true, tokenFormsMaxNumberForAsterix: 30); _chatBotContext.Contexts.Add(context); await _chatBotContext.SaveChangesAsync(); if (!_projectsContexts.ContainsKey(context.ProjectId)) { _projectsContexts.Add(context.ProjectId, new List <ContextWrapper>() { context }); } else { _projectsContexts[context.ProjectId].Add(context); } _logger.LogInformation("Pattern added ({context.Id})", context.Id); return(true); } catch (Exception ex) { _logger.LogError(ex, "can't add context"); return(false); } }