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

FlowerCategoriesDialog.cs 2.1 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
  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 FlowerCategoriesDialog : PagedCarouselDialog<string>
  16. {
  17. private readonly IRepository<FlowerCategory> repository;
  18. public FlowerCategoriesDialog(IRepository<FlowerCategory> repository)
  19. {
  20. this.repository = repository;
  21. }
  22. public override string Prompt
  23. {
  24. get { return Resources.FlowerCategoriesDialog_Prompt; }
  25. }
  26. public override PagedCarouselCards GetCarouselCards(int pageNumber, int pageSize)
  27. {
  28. var pagedResult = this.repository.RetrievePage(pageNumber, pageSize);
  29. var carouselCards = pagedResult.Items.Select(it => new HeroCard
  30. {
  31. Title = it.Name,
  32. Images = new List<CardImage> { new CardImage(it.ImageUrl, it.Name) },
  33. Buttons = new List<CardAction> { new CardAction(ActionTypes.ImBack, Resources.FlowerCategoriesDialog_Select, value: it.Name) }
  34. });
  35. return new PagedCarouselCards
  36. {
  37. Cards = carouselCards,
  38. TotalCount = pagedResult.TotalCount
  39. };
  40. }
  41. public override async Task ProcessMessageReceived(IDialogContext context, string flowerCategoryName)
  42. {
  43. var flowerCategory = this.repository.GetByName(flowerCategoryName);
  44. if (flowerCategory != null)
  45. {
  46. context.Done(flowerCategory.Name);
  47. }
  48. else
  49. {
  50. await context.PostAsync(string.Format(CultureInfo.CurrentCulture, Resources.FlowerCategoriesDialog_InvalidOption, flowerCategoryName));
  51. await this.ShowProducts(context);
  52. context.Wait(this.MessageReceivedAsync);
  53. }
  54. }
  55. }
  56. }
Tip!

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

Comments

Loading...