public async Task <Activity> SaveIdeaAsyncAsync(Activity activity, string body) { var model = JsonConvert.DeserializeObject <CreateIdeaModel>(body); model.StartDate = new DateTime(model.StartDate.AddHours(12).Date.Ticks); var teamAccount = await activity.GetTeamsAccountAsync(); var userObjectId = teamAccount.ObjectId; var graphServiceClient = await AuthenticationHelper.GetGraphServiceClientSafeAsync(userObjectId, Permissions.Delegated); var planService = new PlannerService(graphServiceClient); var ideaService = new IdeaService(graphServiceClient); var plan = await planService.GetTeamPlanAsync(model.Team); if (plan == null) { throw new ApplicationException($"Could not found plan named '{model.Team.DisplayName}'"); } var description = $"Next Steps\r\n{model.NextSteps}\r\n\r\nAligned to Metric\r\n{model.Metric.Name}"; var startDate = new DateTimeOffset(model.StartDate, TimeSpan.FromHours(12)); var plannerTask = await ideaService.CreateAsync(plan.Id, model.Title, model.StartDate, model.Owner.Id, description); var plannerTaskUrl = ideaService.GetIdeaUrl(model.Team.Id, plan.Id, plannerTask.Id); Activity replyActivity = activity.CreateReply(); try { var clientContext = await AuthenticationHelper.GetAppOnlySharePointClientContextAsync(); var metricsService = new MetricsService(clientContext); await metricsService.CreateMetricIdeaAsync(model.Metric.Id, plannerTask, Constants.IdeasPlan.Buckets.NewIdea, plannerTaskUrl); } catch (Exception ex) { replyActivity.Text = "Failed to add item to MetricIdea list: " + ex.Message; } var card = new O365ConnectorCard("Idea created", sections: new O365ConnectorCardSection[] { new O365ConnectorCardSection( facts: new O365ConnectorCardFact[] { new O365ConnectorCardFact("Title", model.Title), new O365ConnectorCardFact("Next Steps", model.NextSteps.Replace("\n", "<br />")), new O365ConnectorCardFact("Aligned to Metric", model.Metric.Name), new O365ConnectorCardFact("Owner", model.Owner.DisplayName), new O365ConnectorCardFact("Start Date", model.StartDate.AddHours(12).ToShortDateString()), }) }); replyActivity.Attachments.Add(card.ToAttachment()); return(replyActivity); }
public IdeaService(GraphServiceClient graphServiceClient) { this.graphServiceClient = graphServiceClient; this.plannerService = new PlannerService(graphServiceClient); this.teamService = new TeamService(graphServiceClient); }
public IdeaService(string token) : base(token) { this._plannerService = new PlannerService(token); }