forked from microsoft/BotBuilder-Samples
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathFlowerCategoriesDialog.cs
64 lines (56 loc) · 2.1 KB
/
FlowerCategoriesDialog.cs
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
namespace ContosoFlowers.Dialogs
{
using System;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using System.Threading.Tasks;
using BotAssets.Dialogs;
using Microsoft.Bot.Builder.Dialogs;
using Microsoft.Bot.Connector;
using Properties;
using Services;
using Services.Models;
[Serializable]
public class FlowerCategoriesDialog : PagedCarouselDialog<string>
{
private readonly IRepository<FlowerCategory> repository;
public FlowerCategoriesDialog(IRepository<FlowerCategory> repository)
{
this.repository = repository;
}
public override string Prompt
{
get { return Resources.FlowerCategoriesDialog_Prompt; }
}
public override PagedCarouselCards GetCarouselCards(int pageNumber, int pageSize)
{
var pagedResult = this.repository.RetrievePage(pageNumber, pageSize);
var carouselCards = pagedResult.Items.Select(it => new HeroCard
{
Title = it.Name,
Images = new List<CardImage> { new CardImage(it.ImageUrl, it.Name) },
Buttons = new List<CardAction> { new CardAction(ActionTypes.ImBack, Resources.FlowerCategoriesDialog_Select, value: it.Name) }
});
return new PagedCarouselCards
{
Cards = carouselCards,
TotalCount = pagedResult.TotalCount
};
}
public override async Task ProcessMessageReceived(IDialogContext context, string flowerCategoryName)
{
var flowerCategory = this.repository.GetByName(flowerCategoryName);
if (flowerCategory != null)
{
context.Done(flowerCategory.Name);
}
else
{
await context.PostAsync(string.Format(CultureInfo.CurrentCulture, Resources.FlowerCategoriesDialog_InvalidOption, flowerCategoryName));
await base.ShowProducts(context);
context.Wait(this.MessageReceivedAsync);
}
}
}
}