public async Task <string> MakeAppointment(MeetingRequestInput meetingRequest, MeetingSlot slot, string AccessToken) { string retval = "Make Appointment Results"; string queryParameter = "/events"; using (var client = new HttpClient()) { using (var req = new HttpRequestMessage(HttpMethod.Post, graphUrl + queryParameter)) { req.Headers.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json")); req.Headers.Authorization = new AuthenticationHeaderValue("Bearer", AccessToken); CalendarEvent ce = CreateCalendarEvent(meetingRequest, slot); var postBody = await Task.Run(() => JsonConvert.SerializeObject(ce)); var httpContent = new StringContent(postBody, Encoding.UTF8, "application/json"); req.Content = httpContent; using (var resp = await client.SendAsync(req)) { var bodyText = await resp.Content.ReadAsStringAsync(); if (resp.IsSuccessStatusCode) { Trace.TraceInformation("Create Event Request Complete."); retval = "Meeting Created!"; } else { Trace.TraceError("Create Event Request Failed to Complete."); retval = "Meeting Not Created"; } } } } return(retval); }
private CalendarEvent CreateCalendarEvent(MeetingRequestInput mri, MeetingSlot slot) { CalendarEvent ce = new CalendarEvent(); var ema = new Emailaddress() { address = mri.OrganizerEmail, name = mri.OrganizerName }; var o = new Organizer() { EmailAddress = ema }; ce.Organizer = o; ce.IsOrganizer = true; ce.Location = new SimpleLocation() { DisplayName = "Skype" }; // TODO: Here's where to integrate with CRM // Probably need three extra items: // ICRMOperations // CRMOperations // CRM DTO of some sort string bodyText = "How can I help you?"; ce.Body = new Body() { Content = bodyText, ContentType = "text" }; // TODO: This assumes we're offsetting from Pacific Time // https://developer.microsoft.com/en-us/graph/docs/api-reference/v1.0/resources/dateTimeTimeZone string timeZoneText = "Pacific Standard Time"; ce.Start = new ZonedDateTime() { dateTime = slot.Start, timeZone = timeZoneText }; ce.End = new ZonedDateTime() { dateTime = slot.Start.AddSeconds(mri.MeetingDuration.Value), timeZone = timeZoneText }; ce.Subject = mri.MeetingSubject; var aema = new Emailaddress() { address = mri.AttendeeEmail, name = mri.AttendeeName }; var a = new InvitedAttendee() { EmailAddress = aema, Type = "Required" }; ce.Attendees = new InvitedAttendee[] { a, }; ce.ResponseRequested = true; // https://developer.microsoft.com/en-us/graph/docs/api-reference/v1.0/api/user_findmeetingtimes ce.Type = "0"; // Single Instance ce.Importance = "1"; // Normal ce.ShowAs = "2"; // Busy ce.IsReminderOn = true; ce.ReminderMinutesBeforeStart = 15; ce.HasAttachments = false; return(ce); }