public async Task <IActionResult> Details(EmailDetailViewModel formData) { try { if (ModelState.IsValid) { await _notificationEmailServices.UpdateEmailDetailAsync(new NotificationEmails { DateTimeModified = DateTimeOffset.Now, EmployeeID = formData.EmployeeId, EmailAddress = formData.EmailAddress, UserAccount = User.Identity.Name, Id = formData.Id }); TempData["Message"] = "Changes saved successfully"; _logger.LogInformation($"Success: successfully updated notification email record by user={@User.Identity.Name.Substring(4)}"); return(RedirectToAction("details", new { id = formData.Id })); } } catch (ApplicationException error) { _logger.LogError( error, $"FAIL: failed to update notification email details {formData.EmailAddress}. Internal Application Error.; user={@User.Identity.Name.Substring(4)}"); ModelState.AddModelError("Beneficiary", $"Failed to update notification email record. {formData.EmailAddress} Contact IT ServiceDesk for support thank you."); } await LoadSelectListsAsync(); return(View(formData)); }
public async Task <IActionResult> Edit(EmailDetailViewModel viewModel) { if (ModelState.IsValid) { await _emailManagementService.EditEmailTemplate(viewModel.EmailTemplate); return(RedirectToAction(nameof(EmailManagementController.Edit), viewModel.EmailTemplate.Id)); } ShowAlertDanger("Could not update email template"); PageTitle = "Edit Email"; return(View("Detail", viewModel)); }
public async Task <IActionResult> Create(EmailDetailViewModel viewModel) { if (ModelState.IsValid) { var newTemplate = await _emailManagementService.CreateEmailTemplate(viewModel.EmailTemplate); return(RedirectToAction(nameof(EmailManagementController.Edit), new { id = newTemplate.Id })); } PageTitle = "Create Email"; return(View("Detail", viewModel)); }
public async Task <IActionResult> Create() { PageTitle = "Create Email"; var site = await GetCurrentSiteAsync(); var viewModel = new EmailDetailViewModel { Action = nameof(Create), EmailTemplate = new EmailTemplate(), }; viewModel.EmailTemplate.FromAddress = site.FromEmailAddress; viewModel.EmailTemplate.FromName = site.FromEmailName; return(View("Detail", viewModel)); }
public async Task <IActionResult> Edit(int id) { PageTitle = "Edit Email"; var viewModel = new EmailDetailViewModel { Action = nameof(Edit), EmailTemplate = await _emailService.GetEmailTemplate(id) }; if (viewModel.EmailTemplate == null) { ShowAlertDanger($"Could not find email template {id}"); RedirectToAction(nameof(EmailManagementController.Index)); } return(View("Detail", viewModel)); }
public async Task <IActionResult> Details(Guid id) { var notificationQuery = await _notificationEmailServices.GetEmailDetailById(id); if (notificationQuery == null) { return(NotFound()); } var model = new EmailDetailViewModel { Id = notificationQuery.Id, EmployeeId = notificationQuery.EmployeeID ?? Guid.Empty, EmailAddress = notificationQuery.EmailAddress }; await LoadSelectListsAsync(); return(View(model)); }
public ActionResult ReloadEmailDetail(long id) { EmailDetailViewModel emailDetail = new EmailDetailViewModel(); emailDetail.Email = new EmailModel(); emailDetail.Attachments = new List <AttachmentModel>(); var responseEmail = _emailService.GetEmailById(id); if (responseEmail != null) { var resultEmail = JsonConvert.DeserializeObject <HrmResultModel <EmailModel> >(responseEmail); if (!CheckPermission(resultEmail)) { //return to Access Denied } else { emailDetail.Email = resultEmail.Results.FirstOrDefault(); } } var responseAttachment = _attachmentService.GetAttackmenByRecordId(id, DataType.Email); if (responseAttachment != null) { var resultAttachment = JsonConvert.DeserializeObject <HrmResultModel <AttachmentModel> >(responseAttachment); if (!CheckPermission(resultAttachment)) { //return to Access Denied } else { emailDetail.Attachments = resultAttachment.Results; } } return(PartialView("~/Administration/Views/Email/_EmailDetail.cshtml", emailDetail)); }
public ActionResult ProcessPayment(EmailDetailViewModel emailInfo) { var selectedEmployeesForPayment = (List <Employee>)TempData["SelectedEmployees"]; emailInfo.EmailBody = emailInfo.EmailBody.Replace("$amount", AppConfig.Config.DefaultBeveragePrice.ToString()); foreach (var employee in selectedEmployeesForPayment) { var dbEmployee = db.Employees.FirstOrDefault(e => e.EmployeeID == employee.EmployeeID); if (dbEmployee == null) { continue; } dbEmployee.Cycle = employee.Cycle + 1; dbEmployee.LastPaymentDate = DateTime.Now; if (ModelState.IsValid) { db.Entry(dbEmployee).State = System.Data.Entity.EntityState.Modified; History history = new History(); history.EmployeeID = employee.EmployeeID; history.Dated = DateTime.Now; history.WeekNumber = AppConfig.Config.CurrentRunningCycle; history.Amount = (int)AppConfig.Config.DefaultBeveragePrice; db.Histories.Add(history); } } try { db.SaveChanges(); } catch { throw new Exception("We can't save the modified data."); } string timeStamp = DateTime.Now.ToString("dd_MMM_yy_h_mm_ss_tt"); string folderPath = DirectoryExtension.GetBaseOrAppDirectory() + "ExcelFiles\\"; var attachmentFilePathAndName = folderPath + timeStamp + ".xls"; var lastTwoYearsHistories = _logic.GetLastTwoYearsHistories(DateTime.Now); ExcelFileCreation(lastTwoYearsHistories, attachmentFilePathAndName); #region Thread for mailing and excel deletion var thread = new Thread(() => { List <Attachment> attachments = new List <Attachment>() { new Attachment(attachmentFilePathAndName) }; attachments[0].Name = AppConfig.Config.EmailAttachmentName + ".xls"; string[] employeeEmails = new string[1]; employeeEmails[0] = selectedEmployeesForPayment.FirstOrDefault().Email; MailSendingWrapper mailWrapper = Mvc.Mailer.GetMailSendingWrapper(employeeEmails, emailInfo.EmailSubject, emailInfo.EmailBody, null, attachments, MailingType.MailBlindCarbonCopy); try { foreach (var employee in selectedEmployeesForPayment) { employeeEmails[0] = employee.Email; mailWrapper = Mvc.Mailer.GetMailSendingWrapper(employeeEmails, emailInfo.EmailSubject, emailInfo.EmailBody.Replace("$name", employee.Name), null, attachments, MailingType.MailBlindCarbonCopy); Mvc.Mailer.SendMail(mailWrapper, false); } } catch (Exception ex) {} finally { mailWrapper.MailMessage.Dispose(); mailWrapper.MailServer.Dispose(); attachments[0] = null; attachments = null; GC.Collect(); System.IO.File.Delete(attachmentFilePathAndName); } }); #endregion thread.Start(); return(RedirectToAction("Index")); }