public static void ScheduleParticipantListEmail(EmailInformation emailInfo, DateTime listDate) { const string jobDescription = "Send list"; var currentEvent = emailInfo.CurrentEvent; RemoveOldListJob(currentEvent, jobDescription); var listJobId = BackgroundJob.Schedule(() => PostalEmailManager.SendListEmail(emailInfo, new ParticipantListEmail()), listDate); AddJobsIntoEvent(listJobId, currentEvent.Id, jobDescription); }
public ActionResult Contact([Bind(Include = "SenderFistName,SenderLastName,From,EmailSubject,EmailBody")] ContactUsEmail model) { if (!ModelState.IsValid) { return(View(model)); } model.To = "*****@*****.**"; PostalEmailManager.SendContactUsEmail(model); Response.Cookies.Add(new HttpCookie("successCookie", "Action is completed successfully")); //remove MessageSent view fom home return(RedirectToAction("Index")); }
public ActionResult DeleteConfirmed(int id) { var user = _service.GetUser(); var @event = _db.Events.Include(ev => ev.Participants) .FirstOrDefault(e => (e.Id == id) && (e.SchedulerUserId == UserId)); //if event hasn't occured notify users of cancellation if (_service.EventHasNotPassed(@event)) { var currentEvent = _db.Events.Where(e => e.Id == @event.Id) .Include(e => e.Participants).FirstOrDefault(); if (currentEvent == null) { return(View("error")); } var participants = currentEvent.Participants.ToList(); foreach (var participant in participants) { var emailInfo = new EmailInformation { CurrentEvent = @event, OrganizerEmail = user.UserName, OrganizerName = user.FirstName, EmailSubject = " cancellation", ParticipantEmail = participant.Email, ParticipantId = participant.Id }; PostalEmailManager.SendEmail(emailInfo, new CancellationEmail()); } //Remove Scheduled emails for deleted Event JobManager.RemoveScheduledJobs(currentEvent); } _db.Events.Remove(@event); _db.SaveChanges(); return(RedirectToAction("Index")); }
public async Task <ActionResult> ForgotPassword(ForgotPasswordViewModel model) { if (ModelState.IsValid) { SchedulerUser user = await UserManager.FindByNameAsync(model.Email); if (user == null) { // Don't reveal that the user does not exist or is not confirmed return(View("ForgotPasswordConfirmation")); } string code = await UserManager.GeneratePasswordResetTokenAsync(user.Id); var callbackUrl = Url.Action("ResetPassword", "Account", new { userId = user.Id, code = code }, protocol: Request.Url.Scheme); //await UserManager.SendEmailAsync(user.Id, "Reset Password", "Please reset your password by clicking <a href=\"" + callbackUrl + "\">here</a>"); #region create and send email with postal instead usermanager var email = new PasswordResetEmail { ReceiverEmail = user.Email, ReceiverName = user.FirstName, AdminEmail = "*****@*****.**", EmailSubject = "Reset password", PassWordRestLink = callbackUrl }; PostalEmailManager.SendResetPassword(email); #endregion return(RedirectToAction("ForgotPasswordConfirmation", "Account", new { userEmail = model.Email })); } // If we got this far, something failed, redisplay form return(View(model)); }
public ActionResult SendEventsInvitation([Bind(Include = "ParticipantsEmails,EventDate,EventId,SendRemainder,ReminderDate,ListDate")] InvitationViewModel model) { var id = model.EventId; if (!ModelState.IsValid) { return(View(ReturnInvitationModel(id))); } //ToDo: change list and remainder dates to swiss time to be used for sending email // get event from database var eventForInvitation = GetEvent(id); eventForInvitation.ListDate = // ReSharper disable once PossibleInvalidOperationException ConvertDateTime.ToSwissTimezone(TimeZoneInfo.ConvertTimeToUtc((DateTime)model.ListDate)); if (model.ReminderDate != null) { eventForInvitation.ReminderDate = ConvertDateTime.ToSwissTimezone(TimeZoneInfo.ConvertTimeToUtc((DateTime)model.ReminderDate)); Elmah.ErrorSignal.FromCurrentContext().Raise(new Exception("{ From Invitation controller sending invitation } Remainder date is on " + eventForInvitation.ReminderDate)); } /* * This is used to check time on the server * when this is deployed */ Elmah.ErrorSignal.FromCurrentContext().Raise(new Exception("{ From Invitation controller sending invitation } List date is on " + eventForInvitation.ListDate)); //Check if invitations can still be sent var notPassed = _service.EventHasNotPassed(eventForInvitation); if (!notPassed) { return(View("_CantInvite", eventForInvitation)); } var unsavedContacts = new UnsavedContactViewModel(); EmailInformation emailInfo = null; var allSaved = false; var contacts = new List <Contact>(); var emails = new List <EmailInformation>(); //loop through emails var emailList = model.ParticipantsEmails.Split(',').ToList(); foreach (var participantEmail in emailList) { var email = _service.RemoveBrackets(participantEmail); //save new participant SaveParticipantInDb(email, eventForInvitation); #region Create and send Email emailInfo = ComposeEmailInfo(eventForInvitation, email); emails.Add(emailInfo); //Send Invitation Email try { PostalEmailManager.SendEmail(emailInfo, new InvitationEmail()); //todo: this is to be removed before deployment for production Elmah.ErrorSignal.FromCurrentContext().Raise(new Exception("Email sent to " + emailInfo.ParticipantEmail)); if (model.SendRemainder) { var remainderDate = Service.GetRemanderDate(eventForInvitation); JobManager.ScheduleRemainderEmail(emails, remainderDate); //todo: this is to be removed before deployment for production Elmah.ErrorSignal.FromCurrentContext().Raise(new Exception("remainder is set at " + remainderDate)); } } catch (Exception exception) { Elmah.ErrorSignal.FromCurrentContext().Raise(exception); return(RedirectToAction("Error")); } #endregion #region after sending email, save unsaved contacts var contactEmails = _contactsController.GetUserContacts(UserId); allSaved = contactEmails.Any(c => c.Email == email); if (allSaved) { continue; } var contact = new Contact { Email = email }; contacts.Add(contact); unsavedContacts.Contacts = contacts; #endregion } #region Scheduling List email // start participant list summary scheduler var listDate = Service.GetListDate(eventForInvitation); JobManager.ScheduleParticipantListEmail(emailInfo, listDate); #endregion //redirect to details if all contacts are saved if (allSaved) { Response.Cookies.Add(new HttpCookie("successCookie", "Action is completed successfully")); return(RedirectToAction("Details", "Events", new { id })); } //Let user save his contacts return view with list of unsaved contacts unsavedContacts.EventId = eventForInvitation.Id; TempData["model"] = unsavedContacts; //Pass list to SaveEmails action return(RedirectToAction("SaveEmails")); }
public static void ScheduleRemainderEmail(List <EmailInformation> emails, DateTime remainderDate) { var remainderJobId = BackgroundJob.Schedule(() => PostalEmailManager.SendRemainder(emails, new RemainderEmail()), remainderDate); AddJobsIntoEvent(remainderJobId, emails.First().CurrentEvent.Id, "Send Remainder"); }
public ActionResult Edit([Bind(Include = "Id,Title,Location,Description,StartDate,EndDate,ReminderDate,ListDate,SchedulerUserId")] Event eventToEdit, int?id) { var results = eventToEdit.StartDate.GetValueOrDefault().CompareTo(eventToEdit.ListDate.GetValueOrDefault()); if (results < 0) { ModelState.AddModelError("dateError", "Enter date before Starting date"); } if (!ModelState.IsValid) { return(View(eventToEdit)); } _db.Entry(eventToEdit).State = EntityState.Modified; _db.SaveChanges(); var remanderDate = Service.GetRemanderDate(eventToEdit); var listDate = Service.GetListDate(eventToEdit); //Remove scheduled jobs of this event JobManager.RemoveScheduledJobs(eventToEdit); #region Send update emails to participants //Get Participants var currentEvent = _db.Events .Where(e => e.Id == eventToEdit.Id) .Include(e => e.Participants) .FirstOrDefault(); if (currentEvent == null) { return(View("Error")); } var participants = currentEvent.Participants.ToList(); var user = _service.GetUser(); EmailInformation emailInfo = null; var emails = new List <EmailInformation>(); //There is no participants if (participants.Count == 0) { return(RedirectToAction("Index")); } foreach (var participant in participants) { var participantId = participant.Id; var detailsUrl = Url.Action("Details", "Response", new RouteValueDictionary(new { id = currentEvent.Id }), "https"); var responseUrl = Url.Action("Response", "Response", new RouteValueDictionary(new { id = currentEvent.Id, pId = participantId }), "https"); emailInfo = new EmailInformation { CurrentEvent = currentEvent, OrganizerName = user.FirstName, OrganizerEmail = user.UserName, ParticipantId = participantId, ParticipantEmail = participant.Email, EmailSubject = " changes.", ResponseUrl = responseUrl, EventDetailsUrl = detailsUrl }; emails.Add(emailInfo); //Notify Participant using postal PostalEmailManager.SendEmail(emailInfo, new EmailInfoChangeEmail()); } #endregion //Schedule remainders only when there is a remainder date if (eventToEdit.ReminderDate != null) { JobManager.ScheduleRemainderEmail(emails, remanderDate); } //Schedule new emails for edited Job JobManager.ScheduleParticipantListEmail(emailInfo, listDate); //JobManager.AddJobsIntoEvent(eventToEdit.Id,"Send List"); return(RedirectToAction("Index")); }