public static IEnumerable <BOT_ANSWER> BOT_ANSWER_GetByPreviousSelectAnswers(int prevAnswerId) { try { IEnumerable <BOT_ANSWER> listAnswer; using (BotDBContext context = new BotDBContext()) { try { //BotDBContext context = new BotDBContext(); BOT_ANSWER prevAnswer = context.BOT_ANSWER.Single(answer => answer.ANSWER_ID == prevAnswerId); if (prevAnswer.QUESTION_ID != null) { listAnswer = context.BOT_ANSWER.Where(answer => answer.LEVEL == prevAnswer.LEVEL && answer.QUESTION_ID == prevAnswer.ANSWER_ID); return(listAnswer.ToList()); } else { listAnswer = context.BOT_ANSWER.Where(answer => answer.LEVEL == prevAnswer.LEVEL && answer.PREVANSWER_ID == prevAnswer.PREVANSWER_ID); return(listAnswer.ToList()); } //return context.BOT_ANSWER.Where(answer => answer.LEVEL == prevAnswer.LEVEL); } catch (Exception ex) { return(null); } } } catch (Exception ex) { return(null); } }
public async Task ShowPreviousSelectionFromCurrentAnswer(IDialogContext context, BOT_ANSWER currentAnswer) { if (currentAnswer.QUESTION_ID != null && currentAnswer.QUESTION_ID != -1) { List <BOT_QUESTION> listPrevQuestions = DAO_QUESTION.BOT_QUESTION_GetPreviousSelectQuestions(currentAnswer.QUESTION_ID.Value).ToList(); if (listPrevQuestions.All(question => question.LEVEL != 1)) { BOT_QUESTION backQuestion = new BOT_QUESTION(); backQuestion.QUESTION_ID = -1; backQuestion.CONTENT = "<-Quay lại"; backQuestion.DOMAIN_ID = -1; backQuestion.FORM_ID = -1; backQuestion.IS_END = true; backQuestion.PREVANSWER_ID = -1; backQuestion.PREVQUESTION_ID = listPrevQuestions[0].PREVQUESTION_ID; backQuestion.QUESTION_TYPE = -1; backQuestion.RECORD_STATUS = -1; backQuestion.SCENARIO_ID = -1; backQuestion.LEVEL = -1; listPrevQuestions.Add(backQuestion); } await ShowListQuestion(context, listPrevQuestions); } if (currentAnswer.PREVANSWER_ID != null && currentAnswer.PREVANSWER_ID != -1) { List <BOT_ANSWER> listPrevAnswers = DAO_ANSWER.BOT_ANSWER_GetByPreviousSelectAnswers(currentAnswer.PREVANSWER_ID.Value).ToList(); BOT_ANSWER backAnswer = new BOT_ANSWER(); backAnswer.ANSWER_ID = -1; if (listPrevAnswers[0].QUESTION_ID != null) { backAnswer.QUESTION_ID = listPrevAnswers[0].QUESTION_ID; } else { backAnswer.QUESTION_ID = -1; } if (listPrevAnswers[0].PREVANSWER_ID != null) { backAnswer.PREVANSWER_ID = listPrevAnswers[0].PREVANSWER_ID; } else { backAnswer.PREVANSWER_ID = -1; } backAnswer.IS_END = true; backAnswer.LEVEL = -1; backAnswer.RECORD_STATUS = -1; backAnswer.CONTENT = "<-Quay lại"; backAnswer.RECORD_STATUS = -1; listPrevAnswers.Add(backAnswer); await ShowListAnswer(context, listPrevAnswers); } }
public async Task ResumeAfterChooseAnswer(IDialogContext context, IAwaitable <BOT_ANSWER> result) { var value = await result; if (value != null) { BotDBService.Entities.BotDBContext DbContext = new BotDBContext(); if (value.ANSWER_ID == -1) { await ShowPreviousSelectionFromCurrentAnswer(context, value); } //else //{ // int id = context.PrivateConversationData.Get<int>("CONVERSATION_ID"); // DAO_CONVERSATIONCONTENT.BOT_CONVERSATIONCONTENT_AddAnswer(id, value.ANSWER_ID, value.CONTENT); //} //BotDBEntities DbContext = new BotDBEntities(); if (DbContext.BOT_ANSWER.Any(answer => answer.PREVANSWER_ID == value.ANSWER_ID)) { List <BOT_ANSWER> ListAnswer = DbContext.BOT_ANSWER.Where(answer => answer.PREVANSWER_ID == value.ANSWER_ID).ToList(); BOT_ANSWER backAnswer = new BOT_ANSWER(); backAnswer.ANSWER_ID = -1; backAnswer.QUESTION_ID = value.QUESTION_ID; backAnswer.IS_END = true; backAnswer.LEVEL = -1; backAnswer.RECORD_STATUS = -1; backAnswer.CONTENT = "<-Quay lại"; backAnswer.PREVANSWER_ID = -1; backAnswer.RECORD_STATUS = -1; ListAnswer.Add(backAnswer); await ShowListAnswer(context, ListAnswer); } if (DbContext.BOT_QUESTION.Any(question => question.PREVANSWER_ID == value.ANSWER_ID)) { List <BOT_QUESTION> ListQuestion = DbContext.BOT_QUESTION.Where(question => question.PREVANSWER_ID == value.ANSWER_ID).ToList(); BOT_QUESTION backQuestion = new BOT_QUESTION(); backQuestion.QUESTION_ID = -1; backQuestion.CONTENT = "<-Quay lại"; backQuestion.DOMAIN_ID = -1; backQuestion.FORM_ID = -1; backQuestion.IS_END = true; backQuestion.PREVANSWER_ID = -1; backQuestion.PREVQUESTION_ID = value.QUESTION_ID; backQuestion.QUESTION_TYPE = -1; backQuestion.RECORD_STATUS = -1; backQuestion.SCENARIO_ID = -1; backQuestion.LEVEL = -1; backQuestion.QUESTION_ID = -1; ListQuestion.Add(backQuestion); await ShowListQuestion(context, ListQuestion); } if (value.IS_END.Value == true) { await context.PostAsync("Cảm ơn bạn đã trò chuyện. Nếu bạn có thắc mắc gì mời bạn chọn tiếp"); List <BOT_QUESTION> listFirstQuestion = DAO_QUESTION.BOT_QUESTION_GetListFirstQuestionByActiveScenario(context.PrivateConversationData.GetValue <string>("DOMAIN_NAME")).ToList(); await this.ShowListQuestion(context, listFirstQuestion); } } }
public async Task ResumeAfterChooseQuestion(IDialogContext context, IAwaitable <BOT_QUESTION> result) { var value = await result; if (value != null) { //string a = ""; //context.PrivateConversationData.TryGetValue<string>("A", out a); if (value.QUESTION_ID == -1) { BOT_QUESTION prevQuestion = DAO_QUESTION.BOT_QUESTION_GetById(value.PREVQUESTION_ID.Value); await ShowPreviousSelectionFromCurrentQuestion(context, prevQuestion); } //else //{ // int id = context.PrivateConversationData.Get<int>("CONVERSATION_ID"); // DAO_CONVERSATIONCONTENT.BOT_CONVERSATIONCONTENT_AddQuestion(id, value.QUESTION_ID, value.CONTENT); //} if (DAO_QUESTIONTYPE.BOT_QUESTIONTYPE_IsGetInfoQuestion(value.QUESTION_TYPE.Value)) { if (value.FORM_NAME.Equals(typeof(CustomerInfoFormModel).Name)) { var customerInfoForm = new FormDialog <Models.FormDialog_Models.CustomerInfoFormModel>(new Models.FormDialog_Models.CustomerInfoFormModel(value), CustomerInfoFormModel.BuildForm, FormOptions.PromptInStart); context.Call(customerInfoForm, CustomerInfoFormCompleted); } else if (value.FORM_NAME.Equals(typeof(CustomerReplyFormModel).Name)) { var customerReplyForm = new FormDialog <Models.FormDialog_Models.CustomerReplyFormModel>(new Models.FormDialog_Models.CustomerReplyFormModel(), CustomerReplyFormModel.BuildForm, FormOptions.PromptInStart); context.Call(customerReplyForm, CustomerReplyFormCompleted); } return; } //BotDBEntities DbContext = new BotDBEntities(); BotDBService.Entities.BotDBContext DbContext = new BotDBContext(); if (DbContext.BOT_ANSWER.Any(answer => answer.QUESTION_ID == value.QUESTION_ID)) { List <BOT_ANSWER> ListAnswer = DbContext.BOT_ANSWER.Where(answer => answer.QUESTION_ID == value.QUESTION_ID).ToList(); if (!ListAnswer.All(answer => answer.IS_END == true)) { BOT_ANSWER backAnswer = new BOT_ANSWER(); backAnswer.ANSWER_ID = -1; backAnswer.QUESTION_ID = value.QUESTION_ID; backAnswer.IS_END = true; backAnswer.LEVEL = -1; backAnswer.RECORD_STATUS = -1; backAnswer.CONTENT = "<-Quay lại"; backAnswer.PREVANSWER_ID = -1; backAnswer.RECORD_STATUS = -1; ListAnswer.Add(backAnswer); } await ShowListAnswer(context, ListAnswer); //PromptDialog.Choice(context, this.ResumeAfterChooseAnswer,ListAnswer, "Click để chọn:", "Không hợp lệ", 3, PromptStyle.Auto); } if (DbContext.BOT_QUESTION.Any(question => question.PREVQUESTION_ID == value.QUESTION_ID)) { List <BOT_QUESTION> ListQuestion = DbContext.BOT_QUESTION.Where(question => question.PREVQUESTION_ID == value.QUESTION_ID).ToList(); // if(value.LEVEL 1) /// { BOT_QUESTION backQuestion = new BOT_QUESTION(); backQuestion.QUESTION_ID = -1; backQuestion.CONTENT = "<-Quay lại"; backQuestion.DOMAIN_ID = -1; backQuestion.FORM_ID = -1; backQuestion.IS_END = true; backQuestion.PREVANSWER_ID = -1; backQuestion.PREVQUESTION_ID = value.QUESTION_ID; backQuestion.QUESTION_TYPE = -1; backQuestion.RECORD_STATUS = -1; backQuestion.SCENARIO_ID = -1; backQuestion.LEVEL = -1; backQuestion.QUESTION_ID = -1; ListQuestion.Add(backQuestion); // } await this.ShowListQuestion(context, ListQuestion); } } else { context.Wait(this.MessageReceiveAsync); } }