public async Task<ActionResult> ListEmailMessages()
        {
            var appState = Session["ClientCredsAddinAppState"] as AppState;

            // get requested mailbox
            var requestedMailbox = Request.Form["Mailbox"];

            // build view model
            var viewModel = new MailViewModel
            {
                AppState = appState,
                SelectedMailbox = requestedMailbox,
                UserListSelectors = GetMailboxSelectOptions(appState.MailboxList)
            };

            // get messages
            var repo = new MessageRepository(viewModel.AppState.AppOnlyGraphToken);
            var mailBox = appState.MailboxList.Where(pair => pair.Value == requestedMailbox).FirstOrDefault();
            var results = await repo.GetMessages(mailBox.Key);

            viewModel.SelectedMailbox = requestedMailbox;
            viewModel.Messages = results;

            return View("Index", viewModel);
        }
    public ActionResult Index() {
      // try to load the app state (set if previously authenticated)
      //  if session value not present, create new app state
      var appState = Session["ClientCredsAddinAppState"] as AppState ?? new AppState();

      // create viewmodel for the view
      var viewModel = new MailViewModel {
        AppState = appState
      };

      // if logged in, get data and add to view model
      if (appState.AppIsAuthorized) {
        // create select list of all users
        viewModel.UserListSelectors = GetMailboxSelectOptions(appState.MailboxList);
      }

      return View(viewModel);
    }
    public async Task<ActionResult> ListEmailMessages() {
      var appState = Session["ClientCredsAddinAppState"] as AppState;

      // get requested mailbox
      var requestedMailbox = Request.Form["Mailbox"];

      // build view model
      var viewModel = new MailViewModel {
        AppState = appState,
        SelectedMailbox = requestedMailbox,
        UserListSelectors = GetMailboxSelectOptions(appState.MailboxList)
      };

      // get messages
      var repo = new MessageRepository(viewModel.AppState.ExchangeOnlineAccessToken);
      var results = await repo.GetMessages(requestedMailbox);

      viewModel.SelectedMailbox = requestedMailbox;
      viewModel.Messages = results;

      return View("Index", viewModel);
    }