Beispiel #1
0
        private async Task <bool> HandleCompetitionInitialization(Activity activity)
        {
            var parameters = ParseCreateCompetitionParameters(activity);

            if (parameters == null)
            {
                return(false);
            }

            var channelData = activity.GetChannelData <TeamsChannelData>();
            var competition = await _competitionService.Create(
                activity.ServiceUrl,
                Guid.Parse(channelData.Tenant.Id),
                channelData.Team.Id,
                channelData.Channel.Id,
                parameters.PlannedDrawTime,
                activity.Locale,
                parameters.OffsetHours,
                parameters.Gift,
                parameters.GiftImageUrl,
                parameters.WinnerCount,
                activity.From.Name,
                activity.From.AadObjectId);

            var mainActivity = _activityBuilder.CreateMainActivity(competition);

            using (var botClient = _botClientFactory.CreateBotClient(activity.ServiceUrl))
            {
                var mainMessage = await botClient.SendToConversationAsync(mainActivity);

                await _competitionService.UpdateMainActivity(competition.Id, mainMessage.Id);
            }

            await _timerService.AddScheduledHttpRequest(
                competition.PlannedDrawTime,
                "POST",
                Url.Action(nameof(CompetitionsController.DrawForCompetition), "Competitions", new { competitionId = competition.Id }));

            return(true);
        }