forked from microsoft/BotBuilder-Samples
-
Notifications
You must be signed in to change notification settings - Fork 0
/
BouquetsDialog.cs
68 lines (59 loc) · 2.29 KB
/
BouquetsDialog.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
65
66
67
68
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 BouquetsDialog : PagedCarouselDialog<Bouquet>
{
private readonly string flowerCategory;
private readonly IRepository<Bouquet> repository;
public BouquetsDialog(string flowerCategory, IRepository<Bouquet> repository)
{
this.flowerCategory = flowerCategory;
this.repository = repository;
}
public override string Prompt
{
get { return string.Format(CultureInfo.CurrentCulture, Resources.BouquetsDialog_Prompt, this.flowerCategory); }
}
public override PagedCarouselCards GetCarouselCards(int pageNumber, int pageSize)
{
var pagedResult = this.repository.RetrievePage(pageNumber, pageSize, (bouquet) => bouquet.FlowerCategory == this.flowerCategory);
var carouselCards = pagedResult.Items.Select(it => new HeroCard
{
Title = it.Name,
Subtitle = it.Price.ToString("C"),
Images = new List<CardImage> { new CardImage(it.ImageUrl, it.Name) },
Buttons = new List<CardAction> { new CardAction(ActionTypes.ImBack, Resources.BouquetsDialog_Select, value: it.Name) }
});
return new PagedCarouselCards
{
Cards = carouselCards,
TotalCount = pagedResult.TotalCount
};
}
public override async Task ProcessMessageReceived(IDialogContext context, string bouquetName)
{
var bouquet = this.repository.GetByName(bouquetName);
if (bouquet != null)
{
context.Done(bouquet);
}
else
{
await context.PostAsync(string.Format(CultureInfo.CurrentCulture, Resources.BouquetsDialog_InvalidOption, bouquetName));
await this.ShowProducts(context);
context.Wait(this.MessageReceivedAsync);
}
}
}
}