public void Should_have_error_when_enquiry_is_null_or_empty()
 {
     var model = new ContactUsModel();
     model.Enquiry = null;
     _validator.ShouldHaveValidationErrorFor(x => x.Enquiry, model);
     model.Enquiry = "";
     _validator.ShouldHaveValidationErrorFor(x => x.Enquiry, model);
 }
 public void Should_have_error_when_fullName_is_null_or_empty()
 {
     var model = new ContactUsModel();
     model.FullName = null;
     _validator.ShouldHaveValidationErrorFor(x => x.FullName, model);
     model.FullName = "";
     _validator.ShouldHaveValidationErrorFor(x => x.FullName, model);
 }
Beispiel #3
0
        public ActionResult ContactUs()
        {
            var model = new ContactUsModel()
            {
                Email = _services.WorkContext.CurrentCustomer.Email,
                FullName = _services.WorkContext.CurrentCustomer.GetFullName(),
                DisplayCaptcha = _captchaSettings.Value.Enabled && _captchaSettings.Value.ShowOnContactUsPage
            };

            return View(model);
        }
        public ActionResult ContactUsSend(ContactUsModel model, bool captchaValid)
        {
            //validate CAPTCHA
            if (_captchaSettings.Enabled && _captchaSettings.ShowOnContactUsPage && !captchaValid)
            {
                ModelState.AddModelError("", T("Common.WrongCaptcha"));
            }

            if (ModelState.IsValid)
            {
                string email = model.Email.Trim();
                string fullName = model.FullName;
				string subject = T("ContactUs.EmailSubject", _storeContext.CurrentStore.Name);

                var emailAccount = _emailAccountService.GetEmailAccountById(EngineContext.Current.Resolve<EmailAccountSettings>().DefaultEmailAccountId);
                if (emailAccount == null)
                    emailAccount = _emailAccountService.GetAllEmailAccounts().FirstOrDefault();

                string from = null;
                string fromName = null;
                string body = Core.Html.HtmlUtils.FormatText(model.Enquiry, false, true, false, false, false, false);
                //required for some SMTP servers
                if (_commonSettings.UseSystemEmailForContactUsForm)
                {
                    from = emailAccount.Email;
                    fromName = emailAccount.DisplayName;
                    body = string.Format("<strong>From</strong>: {0} - {1}<br /><br />{2}", 
                        Server.HtmlEncode(fullName), 
                        Server.HtmlEncode(email), body);
                }
                else
                {
                    from = email;
                    fromName = fullName;
                }
                _queuedEmailService.InsertQueuedEmail(new QueuedEmail()
                {
                    From = from,
                    FromName = fromName,
                    To = emailAccount.Email,
                    ToName = emailAccount.DisplayName,
                    Priority = 5,
                    Subject = subject,
                    Body = body,
                    CreatedOnUtc = DateTime.UtcNow,
                    EmailAccountId = emailAccount.Id,
					ReplyTo = email,
					ReplyToName = fullName
                });

                model.SuccessfullySent = true;
                model.Result = T("ContactUs.YourEnquiryHasBeenSent");

                //activity log
                _customerActivityService.InsertActivity("PublicStore.ContactUs", T("ActivityLog.PublicStore.ContactUs"));

                return View(model);
            }

            model.DisplayCaptcha = _captchaSettings.Enabled && _captchaSettings.ShowOnContactUsPage;
            return View(model);
        }
 public void Should_not_have_error_when_enquiry_is_specified()
 {
     var model = new ContactUsModel();
     model.Enquiry = "please call me back";
     _validator.ShouldNotHaveValidationErrorFor(x => x.Enquiry, model);
 }
 public void Should_not_have_error_when_fullName_is_specified()
 {
     var model = new ContactUsModel();
     model.FullName = "John Smith";
     _validator.ShouldNotHaveValidationErrorFor(x => x.FullName, model);
 }
 public void Should_not_have_error_when_email_is_correct_format()
 {
     var model = new ContactUsModel();
     model.Email = "*****@*****.**";
     _validator.ShouldNotHaveValidationErrorFor(x => x.Email, model);
 }