示例#1
0
 public PurchaseController(UserController userController, IPrestashopApi prestashopApi,
                           IServiceProvider serviceProvider)
 {
     UserController  = userController;
     PrestashopApi   = prestashopApi;
     ServiceProvider = serviceProvider;
 }
示例#2
0
        public OrderProductDialog(UserController userController, ConversationState conversationState, IPrestashopApi prestashopApi,
                                  IConfiguration configuration, PurchaseController purchaseController)
            : base(nameof(OrderProductDialog), userController, conversationState)
        {
            AddDialog(new TextPrompt(nameof(TextPrompt)));
            AddDialog(new TextPrompt("CardValidator", CardJsonValidator));
            AddDialog(new NumberPrompt <int>(nameof(NumberPrompt <int>)));
            AddDialog(new TextPrompt("ProductValidator", ValidateProductAsync));
            AddDialog(new ConfirmPrompt(nameof(ConfirmPrompt)));
            AddDialog(new WaterfallDialog(nameof(WaterfallDialog), new WaterfallStep[]
            {
                CheckPermissionStepAsync,
                LuisConversionStepAsync,
                ProductStepAsync,
                SelectionCardStepAsync,
                DisableCardStepAsync,
                AmountStepAsync,
                ConfirmLineStepAsync,
                AddToCartStepAsync,
            }));

            InitialDialogId    = nameof(WaterfallDialog);
            PermissionLevel    = PermissionLevels.Representative;
            PrestashopApi      = prestashopApi;
            Configuration      = configuration;
            PurchaseController = purchaseController;
        }
示例#3
0
        public MainDialog(IBotServices botServices, TechnicalAssistanceDialog technicalAssistance,
                          OrderProductDialog orderProduct, AskUserInfoDialog infoDialog, ConversationState conversationState, ConfirmOrderDialog confirmOrderDialog,
                          AddProductInfoDialog addProductInfoDialog, UserValidationDialog userValidationDialog, IConfiguration configuration,
                          UserController userController, NotifyController notifyController, IPrestashopApi prestashopApi)
            : base(nameof(MainDialog))
        {
            AddDialog(new TextPrompt(nameof(TextPrompt)));
            AddDialog(orderProduct);
            AddDialog(technicalAssistance);
            AddDialog(infoDialog);
            AddDialog(confirmOrderDialog);
            AddDialog(addProductInfoDialog);
            AddDialog(userValidationDialog);
            AddDialog(new WaterfallDialog(nameof(WaterfallDialog), new WaterfallStep[]
            {
                WelcomeStepAsync,
                InitialStepAsync,
                DispatchStepAsync,
                FinalStepAsync,
            }));

            InitialDialogId       = nameof(WaterfallDialog);
            BotServices           = botServices;
            UserController        = userController;
            NotifyController      = notifyController;
            PrestashopApi         = prestashopApi;
            _conversationAccessor = conversationState.CreateProperty <ConversationData>(nameof(ConversationData));
            Configuration         = configuration;
        }
示例#4
0
文件: Cart.cs 项目: fcapallera/Greta
        public async Task <Attachment> ToAdaptiveCard(IPrestashopApi prestashopApi)
        {
            var card = CardUtils.CreateCardFromJson("confirmOrderCard");

            var user = (await prestashopApi.GetCustomerById(User.PrestashopId.Value)).First();

            //Ara hem convertit el JSON a un AdaptiveCard i editarem els fragments que ens interessen.

            //Primer editem el FactSet (informació de l'usuari que sortirà a la fitxa).
            var containerFact = (card.Body[1] as AdaptiveContainer);
            var factSet       = (containerFact.Items[1] as AdaptiveFactSet);

            factSet.Facts.Add(new AdaptiveFact("Ordered by:", user.GetFullName()));
            factSet.Facts.Add(new AdaptiveFact("Company:", user.Company));

            //Ara editarem la informació que sortirà dels productes
            var containerProducts = (card.Body[3] as AdaptiveContainer);

            foreach (OrderLine orderLine in OrderLine)
            {
                AdaptiveColumnSet columns       = new AdaptiveColumnSet();
                AdaptiveColumn    productColumn = new AdaptiveColumn();

                var product = (await prestashopApi.GetProductById(orderLine.ProductId)).First();

                AdaptiveTextBlock productText = new AdaptiveTextBlock(product.GetNameByLanguage(Languages.English));
                productText.Wrap = true;

                productColumn.Width = "stretch";
                productColumn.Items.Add(productText);
                columns.Columns.Add(productColumn);

                AdaptiveColumn amountColumn = new AdaptiveColumn();

                AdaptiveTextBlock amount = new AdaptiveTextBlock(orderLine.Amount.ToString());
                amount.Wrap = true;

                amountColumn.Width = "auto";
                amountColumn.Items.Add(amount);
                columns.Columns.Add(amountColumn);

                containerProducts.Items.Add(columns);
            }

            var attachment = new Attachment()
            {
                Content     = JsonConvert.DeserializeObject(JsonConvert.SerializeObject(card)),
                ContentType = "application/vnd.microsoft.card.adaptive"
            };

            return(attachment);
        }
示例#5
0
文件: Order.cs 项目: fcapallera/Greta
        public static async Task <Order> BuildOrderAsync(Models.Cart cart, IPrestashopApi prestashopApi)
        {
            var prestaCart = await CartToPost.BuildCartAsync(cart, prestashopApi);

            var postedCart = await prestashopApi.PostCart(prestaCart);

            var customer = (await prestashopApi.GetCustomerById(cart.User.PrestashopId.Value)).First();

            var customerAddresses = await prestashopApi.GetAddressByCustomer(cart.User.PrestashopId.Value);

            var customerAddress = customerAddresses.First();

            var order = new PostOrder(customer, postedCart.Cart, customerAddress);

            double totalPrice = 0;

            foreach (CartRow row in prestaCart.Cart.Rows.Rows)
            {
                var product = (await prestashopApi.GetProductById(row.ProductId)).First();

                totalPrice += product.Price;

                order.OrderRows.Rows.Add(
                    new OrderRow(product, row.Quantity)
                    );
            }

            order.TotalProducts        = totalPrice;
            order.TotalProductsWithTax = totalPrice * 1.21;
            order.TotalPaidTaxExcluded = totalPrice;
            order.TotalPaidTaxIncluded = totalPrice * 1.21;
            order.TotalPaid            = totalPrice * 1.21;

            var prestaOrder = new OrderToPost {
                Order = order
            };

            System.Xml.Serialization.XmlSerializer writer =
                new System.Xml.Serialization.XmlSerializer(typeof(OrderToPost));

            var path = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments) + "//SerializationOverview.xml";

            System.IO.FileStream file = System.IO.File.Create(path);

            writer.Serialize(file, prestaOrder);
            file.Close();

            var postedOrder = await prestashopApi.PostOrder(prestaOrder);

            return(await Task.FromResult(postedOrder.Order));
        }
示例#6
0
        public NotifyController(IBotFrameworkHttpAdapter adapter, ConcurrentDictionary <string, ConversationReference> references,
                                UserController userController, IConfiguration configuration, IPrestashopApi prestashopApi,
                                ConversationState conversationState, CartToOrderDialog cartToOrderDialog)
        {
            _adapter = adapter;
            _conversationReferences = references;
            UserController          = userController;
            _appId             = configuration["MicrosoftAppId"];
            PrestashopApi      = prestashopApi;
            _ConversationState = conversationState;
            CartToOrderDialog  = cartToOrderDialog;

            if (string.IsNullOrEmpty(_appId))
            {
                _appId = Guid.NewGuid().ToString(); //if no AppId, use a random Guid
            }
        }
示例#7
0
        public ConfirmOrderDialog(UserController userController, ConversationState conversationState,
                                  PurchaseController purchaseController, IPrestashopApi prestashopApi) : base(nameof(ConfirmOrderDialog), userController, conversationState)
        {
            AddDialog(new TextPrompt(nameof(TextPrompt), CardJsonValidator));
            AddDialog(new ConfirmPrompt(nameof(ConfirmPrompt)));
            AddDialog(new WaterfallDialog(nameof(WaterfallDialog), new WaterfallStep[]
            {
                CheckPermissionStepAsync,
                CheckOrderStepAsync,
                ShowCardStepAsync,
                DisableCardStepAsync,
                ProcessValueStepAsync,
                FinalStepAsync
            }));

            PermissionLevel    = PermissionLevels.Representative;
            InitialDialogId    = nameof(WaterfallDialog);
            PurchaseController = purchaseController;
            PrestashopApi      = prestashopApi;
        }
示例#8
0
文件: Cart.cs 项目: fcapallera/Greta
        public static async Task <CartToPost> BuildCartAsync(Models.Cart cart, IPrestashopApi prestashopApi)
        {
            var customer = (await prestashopApi.GetCustomerById(cart.User.PrestashopId.Value)).First();

            var prestaCart = new CartToPost()
            {
                Cart = new PostCart(customer)
            };

            var rowCollection = new CartRowCollection();

            foreach (Models.OrderLine line in cart.OrderLine)
            {
                var row = new CartRow(line.ProductId, line.Amount);
                rowCollection.Rows.Add(row);
            }

            prestaCart.Cart.Rows = rowCollection;

            return(await Task.FromResult(prestaCart));
        }
示例#9
0
        public UserValidationDialog(ConversationState conversationState, IPrestashopApi prestashopApi,
                                    UserController userController, NotifyController notifyController) :
            base(nameof(UserValidationDialog), userController, conversationState)
        {
            AddDialog(new TextPrompt(nameof(TextPrompt)));
            AddDialog(new TextPrompt("CustomerValidationPrompt", ValidateCustomerInputAsync));
            AddDialog(new ChoicePrompt(nameof(ChoicePrompt)));
            AddDialog(new WaterfallDialog(nameof(WaterfallDialog), new WaterfallStep[]
            {
                CheckPermissionStepAsync,
                CustomerNameStepAsync,
                DisplayChoiceStepAsync,
                DisableCardStepAsync,
                SetPermissionStepAsync,
                ValidateUserStepAsync
            }));

            NotifyController = notifyController;
            PrestashopApi    = prestashopApi;
            PermissionLevel  = PermissionLevels.Superuser;
            InitialDialogId  = nameof(WaterfallDialog);
        }
示例#10
0
        public CartToOrderDialog(ConversationState conversationState, UserController userController,
                                 PurchaseController purchaseController, IPrestashopApi prestashopApi)
            : base(nameof(CartToOrderDialog), userController, conversationState)
        {
            AddDialog(new TextPrompt(nameof(TextPrompt), CardJsonValidator));
            AddDialog(new TextPrompt(PRICEVALIDATOR, PriceCardValidator));
            AddDialog(new ConfirmPrompt(nameof(ConfirmPrompt)));
            AddDialog(new WaterfallDialog(nameof(WaterfallDialog), new WaterfallStep[]
            {
                CheckPermissionStepAsync,
                AskForActionStepAsync,
                ProcessConfirmationStepAsync,
                DisableCardStepAsync,
                ProcessChoiceStepAsync,
                AssignPricesStepAsync,
                ProcessPricesStepAsync
            }));

            PermissionLevel    = PermissionLevels.Vitrosep;
            PurchaseController = purchaseController;
            InitialDialogId    = nameof(WaterfallDialog);
            PrestashopApi      = prestashopApi;
        }
示例#11
0
        public UserLoginDialog(ConversationState conversationState, IPrestashopApi prestashopApi, IConfiguration configuration,
                               IServiceProvider serviceProvider, NotifyController notifyController, UserController userController)
            : base(nameof(UserLoginDialog), userController, conversationState)
        {
            AddDialog(new TextPrompt("EmailValidator", ValidateEmailAsync));
            AddDialog(new TextPrompt("PasswordValidator", ValidatePasswordAsync));
            AddDialog(new TextPrompt(nameof(TextPrompt)));
            AddDialog(new ConfirmPrompt(nameof(ConfirmPrompt)));
            AddDialog(new WaterfallDialog(nameof(WaterfallDialog), new WaterfallStep[]
            {
                AskEmailStepAsync,
                ConfirmPasswordStepAsync,
                DisableCardStepAsync,
                CheckUserProfileStepAsync,
                AskForVerificationStepAsync
            }));

            PrestashopApi    = prestashopApi;
            Configuration    = configuration;
            ServiceProvider  = serviceProvider;
            NotifyController = notifyController;
            PermissionLevel  = PermissionLevels.Unregistered;
            InitialDialogId  = nameof(WaterfallDialog);
        }
示例#12
0
        async public static Task <RequestedInfo> BuildRequestedInfoAsync(Models.Cart cart, IPrestashopApi prestashopApi)
        {
            var customer = (await prestashopApi.GetCustomerById(cart.User.Id)).First();

            var productString = "";

            foreach (OrderLine line in cart.OrderLine)
            {
                var product = (await prestashopApi.GetProductById(line.ProductId)).First();

                productString += "- " + product.GetNameByLanguage(Languages.English) + "\n\n";
            }

            return(new RequestedInfo(cart.Id, customer.Company, productString));
        }
示例#13
0
        static async public Task <Attachment> CreatePriceAssignationCard(Models.Cart cart, IPrestashopApi prestashopApi)
        {
            var card = CreateCardFromJson("prizeAssignationCard");

            var container = card.Body[3] as AdaptiveContainer;

            int index = 0;

            foreach (OrderLine line in cart.OrderLine)
            {
                var product = (await prestashopApi.GetProductById(line.ProductId)).First();

                var productTitle = new AdaptiveTextBlock
                {
                    Text   = "**" + product.GetNameByLanguage(Languages.English) + "**",
                    Weight = AdaptiveTextWeight.Bolder,
                    Wrap   = true
                };

                var columnSet = new AdaptiveColumnSet();

                var column = new AdaptiveColumn
                {
                    Width = AdaptiveColumnWidth.Stretch
                };

                var reference = new AdaptiveTextBlock
                {
                    Text = product.Reference,
                    Wrap = true
                };

                column.Items.Add(reference);

                var columnInput = new AdaptiveColumn
                {
                    Width = AdaptiveColumnWidth.Auto
                };

                var input = new AdaptiveNumberInput
                {
                    Id          = "InputCount" + index,
                    Placeholder = "Price"
                };
                column.Items.Add(input);
                columnSet.Columns.Add(column);
                columnSet.Columns.Add(columnInput);
                container.Items.Add(columnSet);

                index++;
            }

            return(new Attachment()
            {
                Content = JsonConvert.DeserializeObject(JsonConvert.SerializeObject(card)),
                ContentType = "application/vnd.microsoft.card.adaptive"
            });
        }