/// <summary> /// Gets a collection of calendar events. /// </summary> /// <returns>A collection of all calendar events.</returns> internal async Task<List<EventViewModel>> GetCalendarEventsAsync() { // Make sure we have a reference to the Exchange client var exchangeClient = await AuthenticationHelper.EnsureOutlookClientCreatedAsync(); List<EventViewModel> returnResults = new List<EventViewModel>(); var eventsResults = await exchangeClient.Me.Calendar.Events.OrderBy(e => e.Start).ExecuteAsync(); foreach (IEvent calendarEvent in eventsResults.CurrentPage) { IEvent thisEvent = await GetEventDetailsAsync( calendarEvent.Id); EventViewModel calendarEventModel = new EventViewModel(thisEvent); returnResults.Add(calendarEventModel); } return returnResults; }
/// <summary> /// Gets a collection of events for today's calendar. /// </summary> /// <param name="hoursBefore">int. The beginning of the TimeSpan that defines which events are returned.</param> /// <param name="hoursAfter">int. The end of the TimeSpan that defines which events are returned.</param> /// <returns>A collection of all calendar events found for the specified time range.</returns> internal async Task<List<EventViewModel>> GetTodaysCalendar(int hoursBefore, int hoursAfter) { // Make sure we have a reference to the calendar client var calendarClient = await AuthenticationHelper.EnsureCalendarClientCreatedAsync(); List<EventViewModel> returnResults = new List<EventViewModel>(); // Obtain calendar event data for start times from the range of 6 hours // before now to 6 hours after now. Get the first 48 calender events in the range. // This results in a call to the service. var eventsResults = await (from i in calendarClient.Me.Calendar.Events where i.Start >= DateTimeOffset.Now.Subtract(new TimeSpan(hoursBefore, 0, 0)) && i.Start <= DateTimeOffset.Now.AddHours(hoursAfter) select i).Take(48).ExecuteAsync(); var events = eventsResults.CurrentPage.OrderBy(e => e.Start); foreach (IEvent calendarEvent in events) { IEvent thisEvent = await GetEventDetailsAsync( calendarEvent.Id); EventViewModel calendarEventModel = new EventViewModel(thisEvent); returnResults.Add(calendarEventModel); } return returnResults; }
/// <summary> /// Creates a new event and adds it to the collection. /// </summary> /// <remarks>The event is created locally.</remarks> async void ExecuteNewEventCommandAsync() { var aadClient = await AuthenticationHelper.GetGraphClientAsync(); var currentUser = await (aadClient.Users .Where(i => i.ObjectId == AuthenticationHelper.LoggedInUser) .ExecuteSingleAsync()); var newEvent = new EventViewModel(currentUser.Mail); this.Events.Add(newEvent); this.SelectedEvent = newEvent; LoggingViewModel.Instance.Information = "Click the Update Event button and we'll save the new event to your calendar"; }
/// <summary> /// Creates a new event and adds it to the collection. /// </summary> /// <remarks>The event is created locally.</remarks> async void ExecuteNewEventCommandAsync() { var aadClient = await AuthenticationHelper.EnsureAadGraphClientCreatedAsync(); Microsoft.Office365.ActiveDirectory.IUser currentUser = await (aadClient.Users .Where(i => i.ObjectId == AuthenticationHelper.LoggedInUser) .ExecuteSingleAsync()); var newEvent = new EventViewModel(currentUser.Mail); this.TodaysEvents.Add(newEvent); this.SelectedEvent = newEvent; LoggingViewModel.Instance.Information = "Click the Update Event button and we'll save the new event to your calendar"; }