コード例 #1
0
        public async Task <TaskModuleResponse> FinishSelectDishesSubmit(ITurnContext <IInvokeActivity> turnContext, TaskModuleRequest taskModuleRequest, CancellationToken cancellationToken)
        {
            TeamsBuyContext context  = new TeamsBuyContext();
            var             TaskInfo = new TaskModuleTaskInfo();
            JObject         Data     = JObject.Parse(JsonConvert.SerializeObject(taskModuleRequest.Data));
            var             StoreAndGuidAndDueTime = Data.Property("data").Value.ToString();

            new OrganizeStructureService().RemoveNeedlessStructure(Data);
            string  SelectJson = ProcessAllSelect(Data);
            JObject o          = new JObject();

            o["SelectMenu"] = JArray.Parse(SelectJson);
            bool DecideQuanRem  = true;
            bool Number         = true;
            var  AllSelectDatas = JsonConvert.DeserializeObject <SelectMenuDatagroup>(o.ToString());

            foreach (var item in AllSelectDatas.SelectMenu)
            {
                if (item.Quantity == "0" && item.Remarks != "")
                {
                    DecideQuanRem = false;
                }
                if (Math.Sign(decimal.Parse(item.Quantity)) < 0 || (decimal.Parse(item.Quantity) - Math.Floor(decimal.Parse(item.Quantity))) != 0)
                {
                    Number = false;
                }
            }
            if (DecideQuanRem == true && Number == true)
            {
                //取完整資料
                var OAllOrderDatasStr = ProcessUnifyData(o);
                var SelectObject      = JsonConvert.DeserializeObject <SelectAllDataGroup>(OAllOrderDatasStr);
                SelectObject.UserID = turnContext.Activity.From.Id;
                var ExistGuid = Guid.Parse("cf1ed7b9-ae4a-4832-a9f4-fdee6e492085");
                new OrderDetailService(context).CreateOrderDetail(SelectObject, SelectObject.SelectAllOrders, ExistGuid);

                TaskInfo.Card = new CreateCardService().GetResultClickfood(new OrganizeStructureService().GetOrderID(StoreAndGuidAndDueTime), new OrganizeStructureService().GetStoreName(StoreAndGuidAndDueTime), o.ToString(), new OrganizeStructureService().GetDueTime(StoreAndGuidAndDueTime), turnContext.Activity.From.Name);
                SetTaskInfo(TaskInfo, TaskModuleUIConstants.AdaptiveCard);
                await turnContext.SendActivityAsync(MessageFactory.Attachment(new CreateCardService().GetResultClickfood(new OrganizeStructureService().GetOrderID(StoreAndGuidAndDueTime), new OrganizeStructureService().GetStoreName(StoreAndGuidAndDueTime), o.ToString(), "12:00", turnContext.Activity.From.Name)));
            }
            else
            {
                TaskInfo.Card = new CreateCardService().GetError(turnContext.Activity.From.Name);
                SetTaskInfo(TaskInfo, TaskModuleUIConstants.AdaptiveCard);
                await turnContext.SendActivityAsync(MessageFactory.Attachment(new CreateCardService().GetError(turnContext.Activity.From.Name)));
            }
            return(await Task.FromResult(TaskInfo.ToTaskModuleResponse()));
        }
コード例 #2
0
        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()));
            }
        }
コード例 #3
0
        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()));
            }
        }