Ejemplo n.º 1
0
 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);
 }
Ejemplo n.º 2
0
 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);
 }
Ejemplo n.º 3
0
        public ActionResult ContactUsSend(ContactUsModel model, bool captchaValid)
        {
            //validate CAPTCHA
            if (_captchaSettings.Enabled && _captchaSettings.ShowOnContactUsPage && !captchaValid)
            {
                ModelState.AddModelError("", _localizationService.GetResource("Common.WrongCaptcha"));
            }

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

                var emailAccount = _emailAccountService.GetEmailAccountById(_emailAccountSettings.DefaultEmailAccountId);
                if (emailAccount == null)
                    emailAccount = _emailAccountService.GetAllEmailAccounts().FirstOrDefault();
                if (emailAccount == null)
                    throw new Exception("No email account could be loaded");

                string from = null;
                string fromName = null;
                string body = Core.Html.HtmlHelper.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
                });

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

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

                return View(model);
            }

            model.DisplayCaptcha = _captchaSettings.Enabled && _captchaSettings.ShowOnContactUsPage;
            return View(model);
        }
Ejemplo n.º 4
0
 public ActionResult ContactUs()
 {
     var model = new ContactUsModel()
     {
         Email = _workContext.CurrentCustomer.Email,
         FullName = _workContext.CurrentCustomer.GetFullName(),
         DisplayCaptcha = _captchaSettings.Enabled && _captchaSettings.ShowOnContactUsPage
     };
     return View(model);
 }
Ejemplo n.º 5
0
 public void Should_not_have_error_when_fullName_is_specified()
 {
     var model = new ContactUsModel();
     model.FullName = "John Smith";
     _validator.ShouldNotHaveValidationErrorFor(x => x.FullName, model);
 }
Ejemplo n.º 6
0
 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);
 }
Ejemplo n.º 7
0
 public void Should_not_have_error_when_email_is_correct_format()
 {
     var model = new ContactUsModel();
     model.Email = "*****@*****.**";
     _validator.ShouldNotHaveValidationErrorFor(x => x.Email, model);
 }