public async Task StartAsync(IDialogContext context) { await context.PostAsync("welcome to angkasa pura shopping center, these are our products ?"); Activity replyToConversation = context.MakeMessage() as Activity; replyToConversation.Attachments = new List <Attachment>(); /* * List<CardImage> cardImages = new List<CardImage>(); * cardImages.Add(new CardImage(url: "https://<imageUrl1>")); * * List<CardAction> cardButtons = new List<CardAction>(); * * CardAction plButton = new CardAction() * { * Value = $"https://en.wikipedia.org/wiki/PigLatin", * Type = "openUrl", * Title = "WikiPedia Page" * }; * * cardButtons.Add(plButton); */ List <ReceiptItem> receiptList = new List <ReceiptItem>(); foreach (var item in AirportProduct.GetProducts()) { ReceiptItem lineItem = new ReceiptItem() { Title = $"{item.Name}", Subtitle = $"Product ID: { item.IDProduct}", Text = $"{item.Description}", Image = new CardImage(url: $"{item.UrlImage}"), Price = $"Rp.{item.Harga.ToString("{C:0}")}", Quantity = $"{item.Stock}", Tap = null }; receiptList.Add(lineItem); } ReceiptCard plCard = new ReceiptCard() { Title = "these are our merchant products", //Buttons = cardButtons, Items = receiptList, }; Attachment plAttachment = plCard.ToAttachment(); replyToConversation.Attachments.Add(plAttachment); //send product list await context.PostAsync(replyToConversation); //send confirmation PromptDialog.Confirm( context, AfterShoppingConfirmation, "Do you want to order?", "Oups, I don't understand!", promptStyle: PromptStyle.None); }
public static IForm <ShoppingQuery> BuildForm() { OnCompletionAsyncDelegate <ShoppingQuery> processShopping = async(context, state) => { await Task.Run(async() => { state.NoShopping = $"SP-{DateTime.Now.ToString("dd_MM_yyyy_HH_mm_ss")}"; state.TanggalShopping = DateTime.Now; StateClient stateClient = context.Activity.GetStateClient(); BotData botData = await stateClient.BotState.GetUserDataAsync(context.Activity.ChannelId, context.Activity.From.Id); var myUserData = botData.GetProperty <Cart>("MyCart"); if (myUserData == null) { myUserData = new Cart(); myUserData.Nama = state.Nama; myUserData.NoShopping = state.NoShopping; myUserData.TanggalShopping = state.TanggalShopping; myUserData.Telpon = state.Telpon; myUserData.Total = 0; myUserData.Tax = 0; } if (myUserData.Items == null) { myUserData.Items = new List <CartItem>(); } myUserData.Items.Add(new CartItem() { KodeProduk = state.KodeProduk, Price = state.Price, ProductName = state.ProductName, Qty = state.Qty, Total = state.Qty *state.Price }); double TotAll = 0; //calculate total and tax foreach (var item in myUserData.Items) { TotAll += item.Total; } myUserData.Total = TotAll; myUserData.Tax = TotAll * 0.1; botData.SetProperty <Cart>("MyCart", myUserData); await stateClient.BotState.SetUserDataAsync(context.Activity.ChannelId, context.Activity.From.Id, botData); await AirportData.InsertShoppingOrder(myUserData); } ); }; var builder = new FormBuilder <ShoppingQuery>(false); var form = builder .Field(nameof(Nama)) .Field(nameof(Alamat)) .Field(nameof(Telpon)) .Field(nameof(Email)) .Field(nameof(KodeProduk), validate: async(state, value) => { var result = new ValidateResult { IsValid = true, Value = value, Feedback = "product ready" }; var p = AirportProduct.GetItemByID(value.ToString()); if (p != null) { state.Price = p.Harga; state.ProductName = p.Name; state.Stock = p.Stock; result.Feedback = $"product is available."; result.IsValid = true; } else { result.Feedback = $"product is not available."; result.IsValid = false; } return(result); }) .Field(nameof(Qty), validate: async(state, value) => { var result = new ValidateResult { IsValid = true, Value = value, Feedback = "product ready" }; var ok = int.TryParse(value.ToString(), out int Request); /* * if (ok && Request >= state.Stock && Request > 0) * { * result.Feedback = $"quantity is ok."; * result.IsValid = true; * * } * else * { * result.Feedback = $"stock is not ready, fill with lower quantity."; * result.IsValid = false; * * }*/ return(result); }) .Confirm(async(state) => { var pesan = $"your order is {state.Qty} items of {state.ProductName}, is it pk ?"; return(new PromptAttribute(pesan)); }) .Message("Thanks, we will proceed your order!") .OnCompletion(processShopping) .Build(); return(form); }