Example #1
0
        // Get events.
        public async Task <ActionResult> GetMyEvents()
        {
            ResultsViewModel results = new ResultsViewModel();

            try
            {
                // Get events.
                results.Items = await eventsService.GetMyEvents();
            }
            catch (ServiceException se)
            {
                if ((se.InnerException as AuthenticationException)?.Error.Code == Resource.Error_AuthChallengeNeeded)
                {
                    HttpContext.Request.GetOwinContext().Authentication.Challenge();
                    return(new EmptyResult());
                }
                return(RedirectToAction("Index", "Error", new { message = string.Format(Resource.Error_Message, Request.RawUrl, se.Error.Code, se.Error.Message) }));
            }
            return(View("Events", results));
        }
        // Get events.
        public async Task <ActionResult> Index()
        {
            List <EventsItem> results = new List <EventsItem>();

            try
            {
                // Initialize the GraphServiceClient.
                GraphServiceClient graphClient = SDKHelper.GetAuthenticatedClient();

                // Get events.
                results = await eventsService.GetMyEvents(graphClient);
            }
            catch (ServiceException se)
            {
                if (se.Error.Message == Resource.Error_AuthChallengeNeeded)
                {
                    return(new EmptyResult());
                }

                // Personal accounts that aren't enabled for the Outlook REST API get a "MailboxNotEnabledForRESTAPI" or "MailboxNotSupportedForRESTAPI" error.
                return(RedirectToAction("Index", "Error", new { message = string.Format(Resource.Error_Message, Request.RawUrl, se.Error.Code, se.Error.Message) }));
            }
            return(View(results));
        }