public void Create(DialogCreateViewModel model) { try { Dialog dialog = this.Add(new Dialog() { Active = true, Name = model.Name }); IntentService intentService = new IntentService(); int i = 0; foreach (var intentId in model.IntentIds) { Intent intent = intentService.FirstOrDefault(q => q.Id == intentId); intent.DialogId = dialog.Id; intent.Active = true; intent.Step = model.Steps[i]; intent.Exception = model.Exceptions[i]; ++i; } intentService.SaveChanges(); this.DbSet.SaveChanges(); } catch (Exception e) { throw e; } }
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; } } }