static string FormatDateTimeTimeZone(Microsoft.Graph.DateTimeTimeZone value) { // Get the timezone specified in the Graph value var timeZone = TimeZoneInfo.FindSystemTimeZoneById(value.TimeZone); // Parse the date/time string from Graph into a DateTime var dateTime = DateTime.Parse(value.DateTime); // Create a DateTimeOffset in the specific timezone indicated by Graph var dateTimeWithTZ = new DateTimeOffset(dateTime, timeZone.BaseUtcOffset) .ToLocalTime(); return(dateTimeWithTZ.ToString("g")); }
public async Task <List <MeetingTimeCandidate> > FindMeetingTime() { // Get the group id. //var group = await graphClient.Groups[id].Request().GetAsync(); User me = await graphClient.Me.Request().Select("mail,userPrincipalName").GetAsync(); //Build the list of attendees List <Attendee> attendees = new List <Attendee>(); Attendee attendee = new Attendee(); EmailAddress mailaddress1 = new EmailAddress(); mailaddress1.Address = me.Mail; attendee.EmailAddress = mailaddress1; attendees.Add(attendee); //Build the list of locationcontraints LocationConstraint location = new LocationConstraint(); location.IsRequired = false; location.SuggestLocation = false; List <LocationConstraintItem> locationConstraints = new List <LocationConstraintItem>(); locationConstraints.Add(new LocationConstraintItem { DisplayName = "", LocationEmailAddress = "*****@*****.**" }); //Build the duration Duration duration = new Duration("PT1H"); TimeConstraint timeConstraint = new TimeConstraint(); List <TimeSlot> timeSlots = new List <TimeSlot>(); TimeSlot slot1 = new TimeSlot(); Microsoft.Graph.DateTimeTimeZone start = new Microsoft.Graph.DateTimeTimeZone(); start.DateTime = @"2017-06-10T15:30:00.000"; start.TimeZone = @"W. Europe Standard Time"; Microsoft.Graph.DateTimeTimeZone end = new Microsoft.Graph.DateTimeTimeZone(); end.DateTime = @"2017-06-14T18:00:00.000"; end.TimeZone = @"W. Europe Standard Time"; slot1.Start = start; slot1.End = end; timeSlots.Add(slot1); timeConstraint.Timeslots = timeSlots; //Execute the request var request = graphClient.Me.FindMeetingTimes(attendees, location, timeConstraint, duration, 3, false, false, 50).Request(); MeetingTimeSuggestionsResult meetingSuggestions = await request.PostAsync(); List <MeetingTimeCandidate> meetingTimeCandidates = new List <MeetingTimeCandidate>(); // Create model objects foreach (MeetingTimeSuggestion meetingJson in meetingSuggestions.MeetingTimeSuggestions) { MeetingTimeCandidate candidate = new MeetingTimeCandidate { Confidence = meetingJson.Confidence.Value, MeetingTimeSlotStart = meetingJson.MeetingTimeSlot.Start.DateTime, MeetingTimeSlotEnd = meetingJson.MeetingTimeSlot.End.DateTime, OrganizerAvailability = meetingJson.OrganizerAvailability.Value.ToString() ?? string.Empty, SuggestionHint = meetingJson.SuggestionReason }; meetingTimeCandidates.Add(candidate); } return(meetingTimeCandidates); }