public EmailIndexViewModel GetIndexViewModel() { EmailIndexViewModel emailIndex = new EmailIndexViewModel( useEmailSender: _identityUIEndpoint.UseEmailSender ?? false); return(emailIndex); }
public static EmailIndexViewModel MapFromEmailIndex(this IEnumerable <EmailViewModel> email, int currentPage, int totalPages) { var model = new EmailIndexViewModel { CurrentPage = currentPage, TotalPages = totalPages, Emails = email }; return(model); }
//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> SendEmail(EmailIndexViewModel viewModel) { if (!string.Equals(viewModel.SendValidation, "YES", StringComparison.Ordinal)) { ShowAlertDanger("Emails not sent: you must enter YES in the confirmation field."); return(RedirectToAction(nameof(EmailManagementController.Index))); } else { _logger.LogInformation("Email send requested by {UserId} for email {EmailId} with {SendValidation}", GetActiveUserId(), viewModel.SendEmailTemplateId, viewModel.SendValidation); var jobToken = await _jobService.CreateJobAsync(new Job { JobType = JobType.SendBulkEmails, SerializedParameters = JsonConvert .SerializeObject(new JobDetailsSendBulkEmails { EmailTemplateId = viewModel.SendEmailTemplateId, MailingList = viewModel.EmailList == SubscribedParticipants ? null : viewModel.EmailList, SendToParticipantsToo = viewModel.SendToParticipantsToo }) }); return(View("Job", new ViewModel.MissionControl.Shared.JobViewModel { CancelUrl = Url.Action(nameof(Index)), JobToken = jobToken.ToString(), PingSeconds = 5, SuccessRedirectUrl = "", SuccessUrl = Url.Action(nameof(Index)), Title = "Sending emails..." })); } }
public async Task <IActionResult> SendEmailTest(EmailIndexViewModel viewModel) { if (string.IsNullOrEmpty(viewModel.SendTestRecipients)) { ShowAlertDanger("You must supply one or more email addresses in order to send a test."); return(RedirectToAction(nameof(EmailManagementController.Index))); } else { _logger.LogInformation("Email test requested by {UserId} for email {EmailId} to {Addresses}", GetActiveUserId(), viewModel.SendTestTemplateId, viewModel.SendTestRecipients); var jobToken = await _jobService.CreateJobAsync(new Job { JobType = JobType.SendBulkEmails, SerializedParameters = JsonConvert .SerializeObject(new JobDetailsSendBulkEmails { EmailTemplateId = viewModel.SendTestTemplateId, To = viewModel.SendTestRecipients }) }); return(View("Job", new ViewModel.MissionControl.Shared.JobViewModel { CancelUrl = Url.Action(nameof(Index)), JobToken = jobToken.ToString(), PingSeconds = 5, SuccessRedirectUrl = "", SuccessUrl = Url.Action(nameof(Index)), Title = "Sending test emails..." })); } }
public IActionResult Index() { EmailIndexViewModel emailIndexViewModel = _emailDataService.GetIndexViewModel(); return(View(emailIndexViewModel)); }
public async Task <IActionResult> Index(int page = 1) { var filter = new BaseFilter(); var templateList = await _emailManagementService.GetPaginatedEmailTemplateListAsync(filter); var paginateModel = new PaginateViewModel { ItemCount = templateList.Count, CurrentPage = page, ItemsPerPage = filter.Take.Value }; if (paginateModel.PastMaxPage) { return(RedirectToRoute( new { page = paginateModel.LastPage ?? 1 })); } var currentUser = await _userService.GetDetails(GetActiveUserId()); int subscribedParticipants = await _emailManagementService.GetSubscriberCount(); var addressTypes = new List <SelectListItem>(); var emailLists = await _emailManagementService.GetEmailListsAsync(); foreach (var emailList in emailLists.Where(_ => _.Count > 0)) { var signupsourcedata = new SelectListItem { Text = $"{emailList.Data} ({emailList.Count} subscribed)", Value = emailList.Data }; addressTypes.Add(signupsourcedata); } if (subscribedParticipants > 0) { addressTypes.Add(new SelectListItem { Text = $"Subscribed participants ({subscribedParticipants} subscribed)", Value = SubscribedParticipants }); } var addressSelectList = new SelectList(addressTypes, "Value", "Text"); var viewModel = new EmailIndexViewModel { PaginateModel = paginateModel, EmailTemplates = templateList.Data, SubscribedParticipants = subscribedParticipants, DefaultTestEmail = currentUser?.Email, IsAdmin = currentUser?.IsAdmin == true, AddressTypes = addressSelectList }; if (!string.IsNullOrEmpty(viewModel.SendButtonDisabled)) { ShowAlertWarning("There are no subscribed participants or interested parties to send an email to."); } return(View(viewModel)); }