/// <summary> /// Save document feedback /// </summary> /// <param name="model"></param> /// <returns></returns> public ResponseModel SaveCustomerFeedback(DocumentFeedbackModel model) { if (WorkContext.CurrentUser == null) { throw new EzCMSUnauthorizeException(); } var protectedDocumentEmailTo = _siteSettingService.GetSetting <string>(SettingNames.ProtectedDocumentEmailTo); var emailModel = new ProtectedDocumentEmailModel { Email = WorkContext.CurrentUser.Email, FullName = WorkContext.CurrentUser.FullName, Comment = model.Comment, Path = model.RelativePath }; var emailResponse = _emailTemplateService.ParseEmail(EmailEnums.EmailTemplateType.ProtectedDocumentForm, emailModel); if (emailResponse == null) { return(new ResponseModel { Success = false, Message = T("ProtectedDocument_Message_MissingProtectedDocumentFeedbackEmailTemplate") }); } var emailLog = new EmailLog { To = protectedDocumentEmailTo, ToName = protectedDocumentEmailTo, From = WorkContext.CurrentUser.Email, FromName = WorkContext.CurrentUser.FullName, CC = emailResponse.CC, Bcc = emailResponse.BCC, Subject = emailResponse.Subject, Body = emailResponse.Body, Priority = EmailEnums.EmailPriority.Medium }; var response = _emailLogService.CreateEmail(emailLog, true); return(response.Success ? response.SetMessage(T("ProtectedDocument_Message_FeedbackSuccessfully")) : response.SetMessage(T("ProtectedDocument_Message_FeedbackFailure"))); }
/// <summary> /// Save contact form /// </summary> /// <param name="contact"></param> /// <param name="communication"></param> /// <param name="form"></param> /// <returns></returns> public ResponseModel SaveContactForm(Contact contact, ContactCommunication communication, NameValueCollection form) { var formData = form.AllKeys.SelectMany(form.GetValues, (k, v) => new ContactInformation { Key = k, Value = v }).ToList(); // Save contact SaveForm(contact, communication, formData); #region Generate emails var emailFrom = formData.FirstOrDefault(f => f.Key.Equals("EmailFrom")); var emailTo = formData.FirstOrDefault(f => f.Key.Equals("EmailTo")); if (emailTo != null && !string.IsNullOrEmpty(emailTo.Value)) { var contactInformation = formData.Where(f => !f.Key.Equals("EmailFrom") && !f.Key.Equals("EmailTo")).ToList(); var model = new ContactFormEmailModel { Email = contact.Email, FullName = string.Format("{0} {1}", contact.FirstName, contact.LastName), ContactInformation = contactInformation }; var emailResponse = _emailTemplateService.ParseEmail(EmailEnums.EmailTemplateType.ContactForm, model); if (emailResponse == null) { return(new ResponseModel { Success = false, Message = T("Contact_Message_MissingContactFormEmailTemplate") }); } var emailLog = new EmailLog { To = emailTo.Value, ToName = emailTo.Value, From = emailFrom == null ? string.Empty : emailFrom.Value, FromName = emailFrom == null ? string.Empty : emailFrom.Value, CC = emailResponse.CC, Bcc = emailResponse.BCC, Subject = emailResponse.Subject, Body = emailResponse.Body, Priority = EmailEnums.EmailPriority.Medium }; var response = _emailLogService.CreateEmail(emailLog, true); return(response.Success ? response.SetMessage(T("Contact_Message_ContactFormActionSuccessfully")) : response.SetMessage(T("Contact_Message_ContactFormActionFailure"))); } #endregion return(new ResponseModel { Success = true, Message = T("Contact_Message_ContactFormActionSuccessfully") }); }
/// <summary> /// Submit form /// </summary> /// <param name="formId"></param> /// <param name="contact"></param> /// <param name="communication"></param> /// <param name="collection"></param> /// <returns></returns> public ResponseModel SubmitForm(string formId, Contact contact, ContactCommunication communication, NameValueCollection collection) { try { var id = PasswordUtilities.ComplexDecrypt(formId).ToInt(); var form = GetById(id); if (form != null) { var formData = collection.AllKeys.SelectMany(collection.GetValues, (k, v) => new ContactInformation { Key = k, Value = v }).ToList(); //Save contact and communication contact = _contactService.SaveForm(contact, communication, formData); #region Form Data var formEmailModel = collection.AllKeys.SelectMany(collection.GetValues, (k, v) => new ContactInformation { Key = k.CamelFriendly(), Value = v }).ToList(); var formBuilderSetting = _siteSettingService.LoadSetting <FormBuilderSetting>(); var cacheName = SettingNames.FormBuilderSetting.GetTemplateCacheName(formBuilderSetting.SubmitFormBodyTemplate); var formDataBody = RazorEngineHelper.CompileAndRun(formBuilderSetting.SubmitFormBodyTemplate, formEmailModel, null, cacheName); #endregion if (form.SendSubmitFormEmail && !string.IsNullOrEmpty(form.EmailTo)) { var email = new EmailLog { From = form.FromEmail, FromName = form.FromName, To = form.EmailTo, ToName = form.EmailTo, Subject = formBuilderSetting.SubmitFormSubject, Body = formDataBody }; _emailLogService.CreateEmail(email, true); } if (form.SendNotificationEmail && !string.IsNullOrEmpty(form.NotificationEmailTo)) { var notificationBodyStringBuilder = new StringBuilder(); notificationBodyStringBuilder.AppendLine(form.NotificationBody); notificationBodyStringBuilder.AppendLine(formDataBody); var email = new EmailLog { From = form.FromEmail, FromName = form.FromName, To = form.NotificationEmailTo, ToName = form.NotificationEmailTo, Subject = form.NotificationSubject, Body = notificationBodyStringBuilder.ToString() }; _emailLogService.CreateEmail(email, true); } if (form.SendAutoResponse) { // Get email from form data var emailAddress = formData.FirstOrDefault( f => f.Key.Contains("Email", StringComparison.CurrentCultureIgnoreCase)); if (emailAddress != null && !string.IsNullOrEmpty(emailAddress.Value)) { var toName = contact.FullName; var email = new EmailLog { From = form.FromEmail, FromName = form.FromName, To = emailAddress.Value, ToName = string.IsNullOrWhiteSpace(toName) ? emailAddress.Value : toName, Subject = form.AutoResponseSubject, Body = form.AutoResponseBody }; _emailLogService.CreateEmail(email, true); } } return(new ResponseModel { Success = true, Message = form.ThankyouMessage }); } } catch (Exception) { // Form parameters invalid } return(new ResponseModel { Success = false, Message = T("Form_Message_InvalidFormId") }); }