public void PushToRedis() { IntentService intentService = new IntentService(); PatternService patternService = new PatternService(); List <IntentRedisViewModel> intents = intentService.GetAllForRedis(); List <string> patterns = patternService.GetFullPatterns(); var db = RedisConnectionHelper.Connection.GetDatabase(); db.StringSet(@"BotIntents", JsonConvert.SerializeObject(intents)); db.StringSet(@"BotPatterns", JsonConvert.SerializeObject(patterns)); }
public DialogEditViewModel GetEditViewModel(int dialogId) { Dialog dialog = this.FirstOrDefault(q => q.Id == dialogId && q.Active == true); DialogEditViewModel model = new DialogEditViewModel(); IntentService intentService = new IntentService(); if (dialog != null) { model.Id = dialog.Id; model.Name = dialog.Name; model.Steps = dialog.Intents.Select(q => q.Step.Value).ToList(); model.Exceptions = dialog.Intents.Select(q => q.Exception.Value).ToList(); model.AllIntents = intentService.GetAllForEditingDialog(dialogId); model.SelectedIntents = model.AllIntents.Where(z => z.DialogId == dialogId).Select(z => new IntentViewModel() { Id = z.Id, Name = z.Name }).ToList(); } return(model); }
public void Delete(int dialogId) { var dialog = this.FirstOrDefault(q => q.Id == dialogId); if (dialog != null) { dialog.Active = false; IntentService intentService = new IntentService(); var intents = intentService.Get(q => q.Active == true && q.DialogId == dialogId).ToList(); foreach (var intent in intents) { intent.DialogId = null; intent.Step = -1; intent.Exception = -1; } intentService.SaveChanges(); this.SaveChanges(); } }
public void Update(SimpleDialogEditViewModel model) { Dialog dialog = this.FirstOrDefault(q => q.Id == model.Id && q.Active == true); if (dialog != null) { try { dialog.Name = model.Name; this.DbSet.SaveChanges(); IntentService intentService = new IntentService(); List <Intent> intents = intentService.Get(q => q.DialogId == model.Id).ToList(); foreach (var intent in intents) { intent.Active = false; intent.DialogId = null; } if (model.IntentIds != null) { for (var i = 0; i < model.IntentIds.Length; ++i) { Intent intent = intentService.FirstOrDefault(q => q.Id == model.IntentIds[i]); intent.DialogId = model.Id; intent.Step = model.Steps[i]; intent.Exception = model.Exceptions[i]; intent.Active = true; } } intentService.SaveChanges(); } catch (Exception e) { throw e; } } }