internal static AlexaResponse TopProductsIntentHandler(Request request) { var limit = 10; var criteria = string.Empty; if (request.SlotsList.Any()) { var maxLimit = 10; var limitValue = request.SlotsList.FirstOrDefault(s => s.Key == "Limit").Value; if (!string.IsNullOrWhiteSpace(limitValue) && int.TryParse(limitValue, out limit) && !(limit >= 1 && limit <= maxLimit)) { limit = maxLimit; } criteria = request.SlotsList.FirstOrDefault(s => s.Key == "Criteria").Value; } var output = new StringBuilder(); output.AppendFormat("Here are the top {0} {1}. ", limit, string.IsNullOrWhiteSpace(criteria) ? "products" : criteria); if (IsDemo) { using (var db = new alexaskilldemoEntities()) { if (criteria == "make") { db.Products.Take(limit).OrderByDescending(c => c.Votes).ToList() .ForEach(c => output.AppendFormat("{0}. ", c.Description)); } else { db.Products.Take(limit).OrderByDescending(c => c.Votes).ToList() .ForEach(c => output.AppendFormat("{0} and price {1}. ", c.ProductName, c.Price)); } } } else { var homeStorefrontApi = new HomeStorefrontApi(); var topProducts = homeStorefrontApi.TopProduct().Result; topProducts.ForEach(c => output.AppendFormat("{0} and price {1}. ", c.DisplayName, c.ListPriceWithCurrency)); } return(new AlexaResponse(output.ToString(), new SimpleCard() { Title = "Sitecore storefront", Content = output.ToString() })); }
internal static AlexaResponse AddProductToCartIntentHandler(Request request) { var homeStorefrontApi = new HomeStorefrontApi(); var cartadded = homeStorefrontApi.AddCartLine("Habitat_Master", "6042185").Result; var speechText = new StringBuilder(); speechText.AppendFormat("Product Mira laptop added to your existing cart."); var response = new AlexaResponse(speechText.ToString(), speechText.ToString(), true); return(response); }
internal static AlexaResponse WhereIsTheOrderIntentHandler(Request request) { var output = new StringBuilder(); var homeStorefrontApi = new HomeStorefrontApi(); var recentOrder = homeStorefrontApi.GetRecentOrders().Result; output.AppendFormat("The order placed on {0} in route with delivery. " + "Tracking number <say-as interpret-as=\"spell-out\">{1}</say-as>. Total Amount {2} {3}", recentOrder.Order.OrderDate, recentOrder.Order.TrackingNumber.Substring(0, 5), recentOrder.Order.Total.Amount, recentOrder.Order.Total.CurrencyCode); var response = new AlexaResponse(output.ToString(), output.ToString(), true); return(response); }
internal static AlexaResponse AddProductToCartIntentHandler(Request request) { var homeStorefrontApi = new HomeStorefrontApi(); var cartadded = homeStorefrontApi.AddCartLine("Habitat_Master", "6042185").Result; var text = new StringBuilder(); text.AppendFormat("Product Mira laptop added to your existing cart."); var response = new AlexaResponse(text.ToString(), new SimpleCard() { Title = "Sitecore storefront", Content = text.ToString() }); return(response); }
internal static AlexaResponse ShowMyBasketintentHandler(Request request) { var text = new StringBuilder("Your Current Basket is "); if (IsDemo) { } else { var homeStorefrontApi = new HomeStorefrontApi(); var miniCart = homeStorefrontApi.MiniCart().Result; miniCart.Lines.ForEach(c => text.AppendFormat("{0} and price {1}. ", c.DisplayName, c.LinePrice)); } return(new AlexaResponse(text.ToString(), text.ToString(), true)); }