示例#1
0
        private async Task Subscribe(Message message, string planId)
        {
            try
            {
                var plan = await _planService.GetByIdAsync(planId);

                if (plan == null)
                {
                    await _botService.Client.SendTextMessageAsync(message.Chat.Id, "Plan not found");

                    return;
                }

                PlanServiceModel result = await _botSubscriptionService.CreateBotSubscriptionAsync(
                    new BotSubscriptionServiceModel
                {
                    ChatId = message.Chat.Id.ToString(),
                    PlanId = planId
                });

                await _botService.Client.SendTextMessageAsync(message.Chat.Id,
                                                              $"You have successfully subscribed to '{result.Name}' plan.");
            }
            catch (DomainServicesException exception)
            {
                await _botService.Client.SendTextMessageAsync(message.Chat, exception.Message);
            }
        }
示例#2
0
        private static async Task Subscribe(Message message, string planId)
        {
            IServiceScope           scope = _serviceProvider.CreateScope();
            IBotSubscriptionService botSubscriptionService =
                (IBotSubscriptionService)scope.ServiceProvider.GetService(typeof(IBotSubscriptionService));

            try
            {
                PlanServiceModel result = await botSubscriptionService.CreateBotSubscriptionAsync(
                    new BotSubscriptionServiceModel
                {
                    ChatId = message.Chat.Id.ToString(),
                    PlanId = planId
                });

                await _client.SendTextMessageAsync(message.Chat.Id,
                                                   $"You have successfully subscribed to '{result.Name}' plan.");
            }
            catch (DomainServicesException exception)
            {
                await _client.SendTextMessageAsync(message.Chat.Id, exception.Message);
            }
        }