FormDialog 显示模型 class Bot 框架中的一些特定字段
FormDialog display some specific fields from Model class Bot framework
我想在 RootDialog 中显示 DialogForm。我尝试通过 来做到这一点。但是,我的问题是我有一个模型 class 由 Entity Framework 生成,其中包含一些关于主键(或外键)的字段,我不希望我的客户为其输入输入。所以我的问题是如何制作一个只要求我的客户输入我想要的字段的 DialogForm?
这是我的模型 class:
[Serializable]
public partial class BOT_CUSTOMERINFO
{
public int CUSTOMER_ID { get; set; }
public Nullable<int> DOMAIN_ID { get; set; }
public string NAME { get; set; }
public string EMAIL { get; set; }
public string PHONE { get; set; }
public Nullable<int> RECORD_STATUS { get; set; }
public static IForm<BOT_CUSTOMERINFO> BuildForm()
{
return new FormBuilder<BOT_CUSTOMERINFO>()
.Message("Vui lòng cung cấp thông tin")
.Field(nameof(NAME))
.Field(nameof(EMAIL))
.Field(nameof(PHONE))
.Field(new FieldReflector<BOT_CUSTOMERINFO>(nameof(CUSTOMER_ID)).SetActive((state) => false))
.Build();
}
}
因此我习惯调用 FormDialog:
private BuildFormDelegate<Models.FormDialog_Models.CustomerInfoFormModel> MakeCustomerInfoForm;
internal void CustomerInfoDialog(BuildFormDelegate<Models.BOT_CUSTOMERINFO> makeCustomerInfoForm)
{
this.MakeCustomerInfoForm = makeCustomerInfoForm;
}
public async Task ResumeAfterChooseQuestion(IDialogContext context, IAwaitable<BOT_QUESTION> result)
{
var value = await result;
if(value != null)
{
BotDBEntities DbContext = new BotDBEntities();
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();
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();
await this.ShowListQuestion(context, ListQuestion);
}
if(value.QUESTION_TYPE.Value == 1)
{
var customerInfoForm = new FormDialog<Models.BOT_CUSTOMERINFO>(new Models.BOT_CUSTOMERINFO(), MakeCustomerInfoForm, FormOptions.PromptInStart);
context.Call(customerInfoForm, CustomerInfoFormCompleted);
// var customerInfoForm = new FormDialog<Models.FormDialog_Models.CustomerInfoFormModel>(new Models.FormDialog_Models.CustomerInfoFormModel(),MakeCustomerInfoForm, FormOptions.PromptInStart);
// context.Forward(customerInfoForm, CustomerInfoFormCompleted);
// context.Call(customerInfoForm, CustomerInfoFormCompleted);
//context.Call<Idia<BOT_CUSTOMERINFO>>(BOT_CUSTOMERINFO.BuildForm(), CustomerInfoFormCompleted);
}
}
else
{
context.Wait(this.MessageReceiveAsync);
}
}
在您的 FormBuilder<BOT_CUSTOMERINFO>
声明中,您可以使用 Advanced.Field.SetActive.
停用这些字段
new FormBuilder<BOT_CUSTOMERINFO>
.Field(new FieldReflector<BOT_CUSTOMERINFO>(nameof(CUSTOMER_ID))
.SetActive((state) => false);
我想在 RootDialog 中显示 DialogForm。我尝试通过
[Serializable]
public partial class BOT_CUSTOMERINFO
{
public int CUSTOMER_ID { get; set; }
public Nullable<int> DOMAIN_ID { get; set; }
public string NAME { get; set; }
public string EMAIL { get; set; }
public string PHONE { get; set; }
public Nullable<int> RECORD_STATUS { get; set; }
public static IForm<BOT_CUSTOMERINFO> BuildForm()
{
return new FormBuilder<BOT_CUSTOMERINFO>()
.Message("Vui lòng cung cấp thông tin")
.Field(nameof(NAME))
.Field(nameof(EMAIL))
.Field(nameof(PHONE))
.Field(new FieldReflector<BOT_CUSTOMERINFO>(nameof(CUSTOMER_ID)).SetActive((state) => false))
.Build();
}
}
因此我习惯调用 FormDialog:
private BuildFormDelegate<Models.FormDialog_Models.CustomerInfoFormModel> MakeCustomerInfoForm;
internal void CustomerInfoDialog(BuildFormDelegate<Models.BOT_CUSTOMERINFO> makeCustomerInfoForm)
{
this.MakeCustomerInfoForm = makeCustomerInfoForm;
}
public async Task ResumeAfterChooseQuestion(IDialogContext context, IAwaitable<BOT_QUESTION> result)
{
var value = await result;
if(value != null)
{
BotDBEntities DbContext = new BotDBEntities();
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();
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();
await this.ShowListQuestion(context, ListQuestion);
}
if(value.QUESTION_TYPE.Value == 1)
{
var customerInfoForm = new FormDialog<Models.BOT_CUSTOMERINFO>(new Models.BOT_CUSTOMERINFO(), MakeCustomerInfoForm, FormOptions.PromptInStart);
context.Call(customerInfoForm, CustomerInfoFormCompleted);
// var customerInfoForm = new FormDialog<Models.FormDialog_Models.CustomerInfoFormModel>(new Models.FormDialog_Models.CustomerInfoFormModel(),MakeCustomerInfoForm, FormOptions.PromptInStart);
// context.Forward(customerInfoForm, CustomerInfoFormCompleted);
// context.Call(customerInfoForm, CustomerInfoFormCompleted);
//context.Call<Idia<BOT_CUSTOMERINFO>>(BOT_CUSTOMERINFO.BuildForm(), CustomerInfoFormCompleted);
}
}
else
{
context.Wait(this.MessageReceiveAsync);
}
}
在您的 FormBuilder<BOT_CUSTOMERINFO>
声明中,您可以使用 Advanced.Field.SetActive.
new FormBuilder<BOT_CUSTOMERINFO>
.Field(new FieldReflector<BOT_CUSTOMERINFO>(nameof(CUSTOMER_ID))
.SetActive((state) => false);