private async Task <bool> LoadMailAsync(int page) { LoggingViewModel.Instance.Information = string.Empty; try { //Clear out any mail added in previous calls to LoadMailAsync() if (MailItems != null) { MailItems.Clear(); } else { MailItems = new ObservableCollection <MailItemViewModel>(); } LoggingViewModel.Instance.Information = "Getting mail ..."; //Get mail from Exchange service via API. var mail = await _mailOperations.GetEmailMessagesAsync(page, _pageSize); if (mail.Count == 0 && _currentPage == 1) { LoggingViewModel.Instance.Information = "You have no mail."; _isLastPage = true; } else if (mail.Count == 0) { LoggingViewModel.Instance.Information = "You have no more mail. Click the \"Get Items\" button to reload the first page."; _isLastPage = true; } else { // Load emails into the observable collection that is bound to UI foreach (var mailItem in mail) { MailItems.Add(new MailItemViewModel(mailItem)); } if (mail.Count < _pageSize) { LoggingViewModel.Instance.Information = String.Format("{0} mail items loaded. Click the \"Get Items\" button to reload the first page.", MailItems.Count); _isLastPage = true; } else { LoggingViewModel.Instance.Information = String.Format("{0} mail items loaded. Click the \"Get Items\" button for more.", MailItems.Count); } } } catch (Exception ex) { LoggingViewModel.Instance.Information = "Error loading mail: " + ex.Message; return(false); } return(true); }
private void EmailSearchComplete(object sender, EventArgs e) { if (Account.EmailsFound.Count != 0) { MailItems.Clear(); MailItems.AddRange(Account.EmailsFound); } else { MailItems.Add(new Email() { Subject = "No emails detected - review settings" }); } }