private async Task <DialogTurnResult> CreateIdeaPhase2Async(WaterfallStepContext stepContext, CancellationToken cancellationToken) { var tokenResponse = (TokenResponse)stepContext.Result; if (tokenResponse?.Token == null) { await stepContext.Context.SendActivityAsync(MessageFactory.Text("Login was not successful please try again."), cancellationToken); return(await stepContext.EndDialogAsync(null, cancellationToken)); } var userProfile = await base.UserProfileAccessor.GetAsync(stepContext.Context); var team = userProfile.SelectedTeam; var createIdeaOptions = (CreateIdeaOptions)stepContext.Options; var planService = new PlannerService(tokenResponse.Token); var plan = await planService.GetTeamPlanAsync(team.Id, team.DisplayName); if (plan == null) { var message = $"Failed to create the idea: could not find plan named '{team.DisplayName}'"; await stepContext.Context.SendActivityAsync(message); } else { var description = $"Next Steps\r\n{createIdeaOptions.NextSteps}" + $"\r\n\r\nAligned to Metric\r\n{createIdeaOptions.Metric}"; var ideaService = new IdeaService(tokenResponse.Token); try { await ideaService.CreateAsync(plan.Id, createIdeaOptions.Title, new DateTimeOffset(createIdeaOptions.StartDate.Value, TimeSpan.Zero), createIdeaOptions.Owner, description ); await stepContext.Context.SendActivityAsync("Idea created."); } catch (Exception ex) { var message = $"Failed to create the idea: {ex.Message}"; await stepContext.Context.SendActivityAsync(message); } } return(await stepContext.EndDialogAsync(null, cancellationToken)); }
private async Task SaveIdea(IDialogContext context, IAwaitable <GraphServiceClient> result) { var planService = new PlannerService(await result); var ideaService = new IdeaService(await result); var plan = await planService.GetTeamPlanAsync(Team); if (plan == null) { throw new ApplicationException($"Could not found plan named '{Team.DisplayName}'"); } var plannerTask = await ideaService.CreateAsync(plan.Id, idea.Title, idea.StartDate, idea.Owners.Select(i => i.Id).FirstOrDefault(), idea.Description); var plannerTaskUrl = ideaService.GetIdeaUrl(Team.Id, plan.Id, plannerTask.Id); try { var clientContext = await AuthenticationHelper.GetAppOnlySharePointClientContextAsync(); var metricsService = new MetricsService(clientContext); await metricsService.CreateMetricIdeaAsync(metric.Id, plannerTask, Constants.IdeasPlan.Buckets.NewIdea, plannerTaskUrl); } catch (Exception ex) { await context.SayAsync("Failed to add item to MetricIdea list: " + ex.Message); } await context.SayAsync("Idea created."); //var viewAction = new CardAction(ActionTypes.OpenUrl, "View", value: plannerTaskUrl); //var heroCard = new HeroCard( // text: "Idea created.", // buttons: new List<CardAction> { viewAction }); //var message = context.MakeMessage(); //message.Attachments.Add(heroCard.ToAttachment()); //await context.PostAsync(message); context.Done(idea); }