public async Task <ApiResponse> Post([FromBody] ContactFormData value) { CaptchaResponse response = await _captchaService.Validate(value.CaptchaToken); if (!response.Success) { return(new ApiResponse() { StatusCode = StatusCodes.Status401Unauthorized, ErrorMessage = "Application Error. Please try again later." }); } if (!ModelState.IsValid) { return(new ApiResponse() { StatusCode = StatusCodes.Status400BadRequest, ErrorMessage = "Form errors. Please input correct data" }); } //Save to mongoDb this._contactRepository.AddContact(new Contact() { FullName = value.FullName, Email = value.EmailAddress, Content = value.Message, Answered = false, Submitted = DateTime.Now }); return(new ApiResponse() { StatusCode = StatusCodes.Status200OK }); }
/// <summary> /// From FORMDATA To REQUESTDATA /// </summary> /// <param name="subscriberFormData"></param> /// <returns></returns> public static ContactRequestData ToRequestData(this ContactFormData subscriberFormData) { if (subscriberFormData == null) { return(new ContactRequestData()); } return(new ContactRequestData { ContactDto = subscriberFormData.ToItemData() }); }
public ActionResult Save(ContactFormData form) { form.CreatedDate = DateTime.Now; form.IpAddress = Functions.GetIP(); _unitOfWork.ContactDataForms.Add(form); _unitOfWork.Commit(); SendEmail(form); return(RedirectToAction("Index", new { toastMessage = "Added" })); }
public async Task Create(string name, string email, string subject, string message) { var contactForm = new ContactFormData { Name = name, Email = email, Subject = subject, Message = message, }; await this.contactRepository.AddAsync(contactForm); await this.contactRepository.SaveChangesAsync(); }
public async Task <ActionResult> Contact([FromForm] ContactFormData model) { var sendgrid = new SendGridClient("***************** Sendgrid API Key ********************"); var from = new EmailAddress("*****@*****.**"); var to = new EmailAddress("your email address"); string content = "Sender email: " + model.email + "<br>" + "Message: " + model.message; var msg = MailHelper.CreateSingleEmail(from, to, "Message from " + model.name, content, content); var response = await sendgrid.SendEmailAsync(msg); return(Ok()); }
private async Task <int> CreateContactForm (string name, string email, string subject, string message, IDeletableEntityRepository <ContactFormData> repo) { var contact = new ContactFormData { Name = name, Email = email, Subject = subject, Message = message, }; await repo.AddAsync(contact); await repo.SaveChangesAsync(); return(contact.Id); }
public async Task <JsonResult> Submit(ContactFormModel model) { try { if (!ValidateReCaptcha()) { return(Json(new { status = "invalidRecapcha" }, JsonRequestBehavior.AllowGet)); } if (ModelState.IsValid) { var contactFormData = new ContactFormData(); contactFormData.FullName = model.FullName; contactFormData.Phone = model.Phone; contactFormData.Email = model.Email; contactFormData.Country = model.Country; contactFormData.Message = model.Message; contactFormData.Save(); //send email var subject = Translate("/niteco/emailtemplate/subject").Replace("{FullName}", model.FullName) .Replace("\n", ""); var templateBody = Translate("/niteco/emailtemplate/body"); var body = templateBody.Replace("{FullName}", model.FullName) .Replace("{Email}", model.Email) .Replace("{Phone}", model.Phone) .Replace("{Country}", model.Country) .Replace("{Message}", model.Message) .Replace("\n", "<br>"); var emailToSend = SiteSettingsHandler.Instance.SiteSettings.EmailAdmin; var emailService = ServiceLocator.Current.GetInstance <IEmailService>(); if (!string.IsNullOrEmpty(emailToSend)) { //emailService.SendEmail(emailToSend, model.FullName, subject, body, true); await emailService.SendSendgridEmailAsync(emailToSend, model.Email, model.FullName, subject, body, SiteSettingsHandler.Instance.SiteSettings.SendgridApiKey); } return(Json(new { status = "sucess" }, JsonRequestBehavior.AllowGet)); } return(Json(new { status = "failed" }, JsonRequestBehavior.AllowGet)); } catch (Exception ex) { Logger.Error(ex.Message, ex); return(Json(new { status = "failed" }, JsonRequestBehavior.AllowGet)); } }
public OmsJsonResult SendMessage(ContactFormData contactFormData) { JsonReturnData data = new JsonReturnData(); if (ModelState.IsValid) { data.SuccessMessage = ContactResources.ResourceManager.GetString("Ok", Thread.CurrentThread.CurrentCulture); data.OperationSuccess = true; return(new OmsJsonResult(data)); } data = new JsonReturnData { ErrorMessage = SharedResources.ResourceManager.GetString("ValidationErrors", Thread.CurrentThread.CurrentCulture), OperationSuccess = false, }; return(new OmsJsonResult(data)); }
/// <summary> /// FROM ITEM DATA TO FORM DATA. /// </summary> /// <param name="resultData">the itemData to convert</param> /// <returns>the formdata result</returns> public static ContactFormData ToFormData(this ContactResultData resultData) { if (resultData == null) { return(new ContactFormData()); } ContactFormData formData = new ContactFormData { ContactMessageText = resultData.ContactrDto.ContactMessageText, ContactMessageMail = resultData.ContactrDto.ContactMessageMail, ContactMessageSubject = resultData.ContactrDto.ContactMessageSubject, ContactMessageFullName = resultData.ContactrDto.ContactMessageFirstName }; return(formData); }
/// <summary> /// FROM ITEM DATA TO FORM DATA. /// </summary> /// <param name="itemData">the itemData to convert</param> /// <returns>the formdata result</returns> public static ContactFormData ToFormData(this ContactItemData itemData) { if (itemData == null) { return(new ContactFormData()); } ContactFormData formData = new ContactFormData { ContactMessageFullName = itemData.ContactMessageFirstName, ContactMessageSubject = itemData.ContactMessageSubject, ContactMessageText = itemData.ContactMessageText, ContactMessageMail = itemData.ContactMessageMail }; return(formData); }
public void SendEmail(ContactFormData form) { string userEmail = form.Email; string subject = "ECommerce Website"; string body = "Gracias por contactarte con nosotros, te responderemos en breve."; WebMail.SmtpServer = "smtp.gmail.com"; WebMail.SmtpPort = 587; WebMail.EnableSsl = true; WebMail.UserName = "******"; WebMail.Password = "******"; WebMail.Send(to: userEmail, subject: subject, body: body, isBodyHtml: true); userEmail = "*****@*****.**"; subject = "Contacto: " + form.Subject; body = form.Message; WebMail.Send(to: userEmail, subject: subject, body: body, isBodyHtml: true); }
public void Post([FromBody] ContactFormData contactFormData) { //ADD LAYER BETWEEN CONTROLLER AND EF? var test = contactFormData; var testInfo = new ContactFormData("Alonso", 29, DateTime.Now); using (var db = new AlexaGorillas_dbEntities()) { //VALIDATE INFO //IF GOOD SAVE / IF NOT THEN RETURN ERROR TO CLIENT db.ContactForms.Add(new ContactForm { FirstName = testInfo.FirstName, Age = testInfo.Age, Date = testInfo.Date, DayOfTheWeek = "Monday", Gender = "Male" }); db.SaveChanges(); } }
public ActionResult Send([Bind(Prefix = "Submission")] ContactFormSubmission s) { ContactFormData vd = new ContactFormData() { Submission = s }; vd.Modal = false; vd.Errors = new List <string>(); if (ModelState.IsValid) { s.DateStamp = DateTime.Now; bool emailSent = true; try { _smtpService.SendToMe(new MailAddress(s.EmailAddress, s.Name), EmmaMorris.ContactMeSubject, s.Message); } catch { emailSent = false; } s.EmailSent = emailSent; _contactFormSubmissionWriter.Save(s); _cookieHandler.LastContactFormSubmissionID = s.SubmissionId; return(RedirectToAction("Index", "Home", new { msg = HomeController.Message.emailsent })); } else { vd.Errors = ModelState.Values.Where(v => v.Errors.Any()).SelectMany(v => v.Errors).Select(e => e.ErrorMessage).ToList(); } vd.MainSideBarData = mainSideBarData(); return(View("Index", vd)); }
private DataTable DataForContactForm() { var dataTable = new DataTable(); var CSV_ROW = "{0}*{1}*{2}*{3}*{4}"; foreach (string column in contactFormColumn) { var dcol = new DataColumn(column, typeof(String)); dataTable.Columns.Add(dcol); } var contacts = ContactFormData.GetAll(); foreach (var contact in contacts) { DataRow dr = dataTable.NewRow(); int i = 0; try { string data = string.Format(CSV_ROW, contact.FullName, contact.Phone, contact.Email, contact.Country, contact.Message); char[] delimiter = { '*' }; string[] rows = data.Split(delimiter); while (i < contactFormColumn.Count()) { dr[contactFormColumn[i]] = rows[i]; i++; } } catch (Exception ex) { string what = "ever"; } dataTable.Rows.Add(dr); } return(dataTable); }
private static XDocument ResolveFields(ContactFormData dataItem, EmailTemplate emailTemplate) { XDocument document = XDocument.Parse(emailTemplate.Template); Type interfaceType = typeof(Composite.Forms.ContactFormData); var properties = interfaceType.GetPropertiesRecursively(); List<DynamicTypeMarkupServices.FieldReferenceDefinition> references = DynamicTypeMarkupServices.GetFieldReferenceDefinitions(document, "Composite.Forms.ContactFormData").ToList(); if (references.Count() == 0) { references = DynamicTypeMarkupServices.GetFieldReferenceDefinitions(document, "DynamicType:Composite.Forms.ContactFormData").ToList(); } foreach (DynamicTypeMarkupServices.FieldReferenceDefinition reference in references) { var pr = properties.Find(p => p.Name == reference.FieldName); if (pr != null) { var prValue = pr.GetValue(dataItem, null).ToString().Replace(Environment.NewLine, "<br/>"); XElement xl = XElement.Parse(String.Format("<span>{0}</span>", prValue)); reference.FieldReferenceElement.ReplaceWith(xl); } } return document; }
public static MvcHtmlString ContactForm(this HtmlHelper html, ContactFormData data) { return(html.Partial("ContactForm", data)); }