示例#1
0
        // Get events.
        public async Task <ActionResult> Index()
        {
            List <EventsItem> results         = new List <EventsItem>();
            List <EventsItem> filteredResults = new List <EventsItem>();

            if (Session["facultyMail"] != null)
            {
                try
                {
                    // Initialize the GraphServiceClient.
                    GraphServiceClient graphClient = SDKHelper.GetAuthenticatedClient();

                    // Get events.
                    results = await eventsService.GetMyAppointments(graphClient);

                    if (results != null && results.Any())
                    {
                        foreach (EventsItem item in results)
                        {
                            foreach (Attendee attendee in item.Attendees)
                            {
                                if (attendee.EmailAddress.Address.Equals(Session["facultyMail"].ToString()))
                                {
                                    filteredResults.Add(item);
                                }
                            }
                        }
                    }
                }
                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("Index", filteredResults));
            }
            return(RedirectToAction("Home", "Home"));
        }