Register
Login
Resources
Docs Blog Datasets Glossary Case Studies Tutorials & Webinars
Product
Data Engine LLMs Platform Enterprise
Pricing Explore
Connect to our Discord channel

BouquetsDialog.cs 2.3 KB

You have to be logged in to leave a comment. Sign In
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
  1. namespace ContosoFlowers.Dialogs
  2. {
  3. using System;
  4. using System.Collections.Generic;
  5. using System.Globalization;
  6. using System.Linq;
  7. using System.Threading.Tasks;
  8. using BotAssets.Dialogs;
  9. using Microsoft.Bot.Builder.Dialogs;
  10. using Microsoft.Bot.Connector;
  11. using Properties;
  12. using Services;
  13. using Services.Models;
  14. [Serializable]
  15. public class BouquetsDialog : PagedCarouselDialog<Bouquet>
  16. {
  17. private readonly string flowerCategory;
  18. private readonly IRepository<Bouquet> repository;
  19. public BouquetsDialog(string flowerCategory, IRepository<Bouquet> repository)
  20. {
  21. this.flowerCategory = flowerCategory;
  22. this.repository = repository;
  23. }
  24. public override string Prompt
  25. {
  26. get { return string.Format(CultureInfo.CurrentCulture, Resources.BouquetsDialog_Prompt, this.flowerCategory); }
  27. }
  28. public override PagedCarouselCards GetCarouselCards(int pageNumber, int pageSize)
  29. {
  30. var pagedResult = this.repository.RetrievePage(pageNumber, pageSize, (bouquet) => bouquet.FlowerCategory == this.flowerCategory);
  31. var carouselCards = pagedResult.Items.Select(it => new HeroCard
  32. {
  33. Title = it.Name,
  34. Subtitle = it.Price.ToString("C"),
  35. Images = new List<CardImage> { new CardImage(it.ImageUrl, it.Name) },
  36. Buttons = new List<CardAction> { new CardAction(ActionTypes.ImBack, Resources.BouquetsDialog_Select, value: it.Name) }
  37. });
  38. return new PagedCarouselCards
  39. {
  40. Cards = carouselCards,
  41. TotalCount = pagedResult.TotalCount
  42. };
  43. }
  44. public override async Task ProcessMessageReceived(IDialogContext context, string bouquetName)
  45. {
  46. var bouquet = this.repository.GetByName(bouquetName);
  47. if (bouquet != null)
  48. {
  49. context.Done(bouquet);
  50. }
  51. else
  52. {
  53. await context.PostAsync(string.Format(CultureInfo.CurrentCulture, Resources.BouquetsDialog_InvalidOption, bouquetName));
  54. await this.ShowProducts(context);
  55. context.Wait(this.MessageReceivedAsync);
  56. }
  57. }
  58. }
  59. }
Tip!

Press p or to see the previous file or, n or to see the next file

Comments

Loading...