//For displaying all emails (with pagination of 10 per page) public async Task <IActionResult> ListAllStatusEmails(int?currentPage, string search = null) { GetEmailsFromGmail(); string userId = FindUserById(); int currPage = currentPage ?? 1; int totalPages = await _emailService.GetPageCount(10); IEnumerable <Email> emailAllResults = null; if (!string.IsNullOrEmpty(search)) { //For email search emailAllResults = await _emailService.SearchEmails(search, currPage, userId); log.Info($"User searched for {search}."); } else { emailAllResults = await _emailService.GetAllStatusEmails(currPage, userId); log.Info($"Displayed all emails list."); } IEnumerable <EmailViewModel> emailsListing = emailAllResults .Select(m => EmailMapper.MapFromEmail(m, _emailService)); EmailIndexViewModel emailModel = EmailMapper.MapFromEmailIndex(emailsListing, currPage, totalPages); //For pagination buttons and distribution emailModel.CurrentPage = currPage; emailModel.TotalPages = totalPages; if (totalPages > currPage) { emailModel.NextPage = currPage + 1; } if (currPage > 1) { emailModel.PreviousPage = currPage - 1; } return(View(emailModel)); }
public async Task <IActionResult> ListAllStatusEmails(int?currentPage, string search = null) { GetEmailsFromGmail(); var userId = User.FindFirstValue(ClaimTypes.NameIdentifier); var currPage = currentPage ?? 1; int totalPages = await _emailService.GetPageCount(10); IEnumerable <Email> emailAllResults = null; if (!string.IsNullOrEmpty(search)) { emailAllResults = await _emailService.SearchEmails(search, currPage, userId); log.Info($"User searched for {search}."); } else { emailAllResults = await _emailService.GetAllStatusEmails(currPage, userId); log.Info($"Displayed all emails list."); } var emailsListing = emailAllResults .Select(m => EmailMapper.MapFromEmail(m, _emailService)); var emailModel = EmailMapper.MapFromEmailIndex(emailsListing, currPage, totalPages); emailModel.CurrentPage = currPage; emailModel.TotalPages = totalPages; if (totalPages > currPage) { emailModel.NextPage = currPage + 1; } if (currPage > 1) { emailModel.PreviousPage = currPage - 1; } return(View(emailModel)); }