protected override async Task <TaskModuleResponse> OnTeamsTaskModuleSubmitAsync(ITurnContext <IInvokeActivity> turnContext, TaskModuleRequest taskModuleRequest, CancellationToken cancellationToken) { var factory = new AdaptiveCardDataFactory(turnContext, taskModuleRequest); var fetchType = factory.GetCardActionType(); if (fetchType?.Equals("ResultStoreCard") == true) { //create group buy card var orderId = Guid.NewGuid().ToString(); var data = factory.GetGroupBuyCard(orderId); _orderService.CreateOrder(orderId, turnContext.Activity.ChannelId, data.StoreName); var cardService = new CreateCardService2(); await turnContext.SendActivityAsync(MessageFactory.Attachment(cardService.GetStore(data))); //create scheduler var services = await SchedulerFactory.GetAllSchedulers(); var scheduler = new ScheduleCreator(services[0], turnContext.Activity.From.Id, orderId); var dueTime = DateTime.Parse(data.DueTime); scheduler.CreateSingleGroupBuy(dueTime); AddConversationReference(turnContext.Activity as Activity); return(null); } if (fetchType?.Equals("FetchSelectedFoods") == true) { var card = new CreateCardService2().GetChosenFoodFromMenu(factory); if (card.Name?.Contains("error") == true) { var taskInfo = new TaskModuleTaskInfo(); taskInfo.Card = card; return(await Task.FromResult(taskInfo.ToTaskModuleResponse())); } else { await turnContext.SendActivityAsync(MessageFactory.Attachment(card)); new CreateCardService2().GetChosenFoodFromMenuCreateOrderDetail(factory, turnContext.Activity.From.Id); return(null); } } else if (fetchType?.Equals("GetCustomizedStore") == true) { //get order data var data = factory.GetCardData <StoreOrderDuetime>(); data.DueTime = JObject.FromObject(factory.Request.Data).GetValue("DueTime").ToString(); data.OrderID = Guid.NewGuid().ToString(); //create an order and group-buy card _orderService.CreateOrder(data.OrderID, turnContext.Activity.ChannelId, data.StoreName); await turnContext.SendActivityAsync(MessageFactory.Attachment(_menuOrderService.GetStore(factory, data.OrderID))); //create scheduler var services = await SchedulerFactory.GetAllSchedulers(); var scheduler = new ScheduleCreator(services[0], turnContext.Activity.From.Id, data.OrderID); var dueTime = DateTime.Parse(data.DueTime); scheduler.CreateSingleGroupBuy(dueTime); AddConversationReference(turnContext.Activity as Activity); return(null); } //ting 按下按鈕傳資料到data else if (fetchType?.Equals("GetCustomizedMenu") == true) { var teamsId = turnContext.Activity.GetChannelData <TeamsChannelData>()?.Tenant?.Id; var menu = _menuService.CreateMenu(factory, teamsId); if (menu == null) { await turnContext.SendActivityAsync(MessageFactory.Text("Please create your store first!")); } else { _menuService.CreateMenuDetail(factory, menu.MenuId); await turnContext.SendActivityAsync(MessageFactory.Text("Create Successfully!")); var NewId = factory.GetCardData <StoreInfoData>().Name; var CustomMenucard = _customMenuService.CallCustomeCard(NewId); var activity = MessageFactory.Attachment(CustomMenucard); activity.Id = NewId; //指定要更新的activity await turnContext.UpdateActivityAsync(activity, cancellationToken); } return(null); } else if (fetchType?.Equals("GetCustomizedMenuDetail") == true) { var menu = factory.GetCardData <StoreInfoData>().Guid; _menuService.CreateMenuDetail(factory, Guid.Parse(menu)); await turnContext.SendActivityAsync(MessageFactory.Text("Create Successfully!")); return(null); } else if (fetchType?.Equals("reserveStore") == true) { var orderId = Guid.NewGuid().ToString(); var data = factory.GetGroupBuyCard(orderId); turnContext.Activity.Value = JsonConvert.SerializeObject(data); turnContext.Activity.Type = "message"; await Dialog.RunAsync(turnContext, ConversationState.CreateProperty <DialogState>(nameof(DialogState)), cancellationToken); return(null); } //育銨 else { var TaskInfo = new TaskModuleTaskInfo(); TaskInfo.Card = new CreateCardService2().GetResultCustomizedModification(factory); new CreateCardService2().SetTaskInfo(TaskInfo, TaskModuleUIConstants.UpdateMenu); return(await Task.FromResult(TaskInfo.ToTaskModuleResponse())); } }
protected async override Task <TaskModuleResponse> OnTeamsTaskModuleFetchAsync(ITurnContext <IInvokeActivity> turnContext, TaskModuleRequest taskModuleRequest, CancellationToken cancellationToken) { var TaskInfo = new TaskModuleTaskInfo(); var factory = new AdaptiveCardDataFactory(turnContext, taskModuleRequest); var fetchType = factory.GetCardActionType(); var service = new CreateCardService2(); var taskInfo = new TaskModuleTaskInfo(); //ting create Customized menu taskmodule if (fetchType?.Equals("createmenu") == true) { var activityId = factory.GetCardData <string>(); taskInfo.Card = service.GetCreateMenu(activityId); return(await Task.FromResult(taskInfo.ToTaskModuleResponse())); } //create menu detail else if (fetchType?.Equals("CreateMenuDetail") == true) { var menu = factory.GetCardData <string>(); taskInfo.Card = service.GetCreateMenuDetail(menu); return(await Task.FromResult(taskInfo.ToTaskModuleResponse())); } //Group Buy Open Menu if (fetchType?.Equals("OpenMenuTaskModule") == true) { taskInfo.Card = await service.CreateMenu(factory); return(await Task.FromResult(taskInfo.ToTaskModuleResponse())); } // Customized Card if (fetchType?.Equals("Customized") == true) { var TenantId = turnContext.Activity.GetChannelData <TeamsChannelData>()?.Tenant?.Id; TaskInfo.Card = _menuOrderService.CreateMenuOrderAttachment(TenantId); return(await Task.FromResult(TaskInfo.ToTaskModuleResponse())); } else if (fetchType?.Equals("GetCustomizedMenu") == true) { taskInfo.Card = await _menuOrderService.CreateMenu(factory); return(await Task.FromResult(taskInfo.ToTaskModuleResponse())); } //家寶 if (fetchType?.Equals("GetStore") == true) { taskInfo.Card = await new GetStoreList().CreateStoresModule(factory, null); return(await Task.FromResult(taskInfo.ToTaskModuleResponse())); } else if (fetchType.Equals("reserveStore")) { taskInfo.Card = await new GetStoreList().CreateStoresModule(factory, "reserveStore"); return(await Task.FromResult(taskInfo.ToTaskModuleResponse())); } //育銨 else if (fetchType?.Equals("GetChosenFoodFromMenuData") == true) { TaskInfo.Card = new CreateCardService2().GetChosenFoodFromMenuModule(factory); service.SetTaskInfo(TaskInfo, TaskModuleUIConstants.ChosenData); return(await Task.FromResult(TaskInfo.ToTaskModuleResponse())); } else if (fetchType?.Equals("GetResultTotalFromModule") == true) { TaskInfo.Card = new CreateCardService2().GetResultTotalFromMenuModule(factory); service.SetTaskInfo(TaskInfo, TaskModuleUIConstants.ChosenData); return(await Task.FromResult(TaskInfo.ToTaskModuleResponse())); } else { taskInfo.Card = service.GetCustomizedModification(factory); service.SetTaskInfo(taskInfo, TaskModuleUIConstants.UpdateMenu); return(await Task.FromResult(taskInfo.ToTaskModuleResponse())); } }