Ejemplo n.º 1
0
        public async Task <TaskModuleResponse> GetModifyModuleData(ITurnContext <IInvokeActivity> turnContext, TaskModuleRequest taskModuleRequest, CancellationToken cancellationToken)
        {
            var             TaskInfo       = new TaskModuleTaskInfo();
            TeamsBuyContext context        = new TeamsBuyContext();
            var             asJobject      = JObject.FromObject(taskModuleRequest.Data);
            var             Value          = asJobject.ToObject <CardTaskFetchValue <string> >()?.Data;
            var             MenuOrderData  = new MenuDetailService(context).GetMenuOrder(Value).ToList();
            var             MenuOrderStore = new MenuService(context).GetMenuOrder(Value).Store;

            TaskInfo.Card = new CreateCardService().GetCustomizedModification(MenuOrderStore, MenuOrderData, Value);
            SetTaskInfo(TaskInfo, TaskModuleUIConstants.UpdateMenu);
            return(await Task.FromResult(TaskInfo.ToTaskModuleResponse()));
        }
        public Attachment GetResultCustomizedModification(AdaptiveCardDataFactory dataFactory)
        {
            TeamsBuyContext context = new TeamsBuyContext();
            var             MenuId  = dataFactory.GetCardData <ModifyData>().MenuId;

            dataFactory.ModifyMenuData(MenuId);
            var menuDetails    = new MenuDetailService(context).GetMenuOrder(MenuId).ToList();
            var MenuOrderStore = new MenuService(context).GetMenuOrder(MenuId).Store;

            string[] ItemsName = new string[] { "Food Name", "Price" };
            var      card      = NewAdaptiveCard()
                                 .AddElement(new AdaptiveTextBlock()
            {
                Text = MenuOrderStore
            })
                                 .AddRow(new AdaptiveColumnSet().
                                         AddColumnsWithStrings(ItemsName)
                                         );

            for (var i = 0; i < menuDetails.Count; i++)
            {
                card.AddRow(new AdaptiveColumnSet()      //加入一列到卡片裡
                            .AddCol(new AdaptiveColumn() //加入一欄位到一列
                                    .AddElement(new AdaptiveTextBlock()
                {
                    Text = menuDetails[i].ProductName
                })                                       //在欄位內加入餐點名稱的文字
                                    )
                            .AddCol(new AdaptiveColumn() //加入一欄位到一列
                                    .AddElement(new AdaptiveTextBlock()
                {
                    Text = decimal.Round(menuDetails[i].Amount).ToString()
                })                                                                                                              //加入餐點價格
                                    )
                            );
            }
            return(new Attachment()
            {
                ContentType = AdaptiveCard.ContentType, Content = card
            });
        }
        public Attachment GetCustomizedModification(AdaptiveCardDataFactory dataFactory)
        {
            TeamsBuyContext context        = new TeamsBuyContext();
            var             MenuId         = dataFactory.GetCardData <ModifyData>().MenuId;
            var             menuDetails    = new MenuDetailService(context).GetMenuOrder(MenuId).ToList();
            var             MenuOrderStore = new MenuService(context).GetMenuOrder(MenuId).Store;
            var             ModifyData     = new CardDataModel <ModifyData>()
            {
                Type  = "CustomizedModification",
                Value = new ModifyData()
                {
                    MenuId = MenuId
                }
            };

            string[] ItemsName = new string[] { "Food Name", "Price" };
            var      card      =
                NewAdaptiveCard()
                .AddRow(new AdaptiveColumnSet()
            {
                Separator = true
            }
                        .AddCol(new AdaptiveColumn()
                                .AddElement(new AdaptiveTextInput()
            {
                Id = MenuOrderStore + "1", Value = MenuOrderStore
            }))
                        .AddCol(new AdaptiveColumn()
                                .AddElement(new AdaptiveTextBlock()
            {
                Text = ""
            })
                                ))
                .AddRow(new AdaptiveColumnSet().
                        AddColumnsWithStrings(ItemsName)
                        );

            for (var i = 0; i < menuDetails.Count; i++)
            {
                card.AddRow(new AdaptiveColumnSet()      //加入一列到卡片裡
                            .AddCol(new AdaptiveColumn() //加入一欄位到一列
                                    .AddElement(new AdaptiveTextInput()
                {
                    Id = menuDetails[i].ProductName + i.ToString(), Value = menuDetails[i].ProductName
                })                                       //在欄位內加入餐點名稱的文字
                                    )
                            .AddCol(new AdaptiveColumn() //加入一欄位到一列
                                    .AddElement(new AdaptiveTextInput()
                {
                    Id = menuDetails[i].Amount + i.ToString(), Value = decimal.Round(menuDetails[i].Amount).ToString()
                })                                                                                                                                                          //加入餐點價格
                                    )
                            );
            }
            card
            .AddActionsSet(
                NewActionsSet()
                .AddActionToSet(
                    new AdaptiveSubmitAction().SetOpenTaskModule("Edit", JsonConvert.SerializeObject(ModifyData))   //勿必要將傳出去的資料進行Serialize
                    )
                );
            return(new Attachment()
            {
                ContentType = AdaptiveCard.ContentType, Content = card
            });
        }