public void Should_have_error_when_fullName_is_null_or_empty()
 {
     var model = new ContactVendorModel();
     model.FullName = null;
     _validator.ShouldHaveValidationErrorFor(x => x.FullName, model);
     model.FullName = "";
     _validator.ShouldHaveValidationErrorFor(x => x.FullName, model);
 }
 public void Should_have_error_when_enquiry_is_null_or_empty()
 {
     var model = new ContactVendorModel();
     model.Enquiry = null;
     _validator.ShouldHaveValidationErrorFor(x => x.Enquiry, model);
     model.Enquiry = "";
     _validator.ShouldHaveValidationErrorFor(x => x.Enquiry, model);
 }
        public ActionResult ContactVendorSend(ContactVendorModel model, bool captchaValid)
        {
            if (!_vendorSettings.AllowCustomersToContactVendors)
                return RedirectToRoute("HomePage");

            var vendor = _vendorService.GetVendorById(model.VendorId);
            if (vendor == null || !vendor.Active || vendor.Deleted)
                return RedirectToRoute("HomePage");

            //validate CAPTCHA
            if (_captchaSettings.Enabled && _captchaSettings.ShowOnContactUsPage && !captchaValid)
            {
                ModelState.AddModelError("", _localizationService.GetResource("Common.WrongCaptcha"));
            }

            model.VendorName = vendor.GetLocalized(x => x.Name);

            if (ModelState.IsValid)
            {
                string email = model.Email.Trim();
                string fullName = model.FullName;

                string subject = _commonSettings.SubjectFieldOnContactUsForm ?
                    model.Subject :
                    string.Format(_localizationService.GetResource("ContactVendor.EmailSubject"), _storeContext.CurrentStore.GetLocalized(x => x.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;
                string fromName;
                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 = vendor.Email,
                    ToName = vendor.Name,
                    ReplyTo = email,
                    ReplyToName = fullName,
                    Priority = QueuedEmailPriority.High,
                    Subject = subject,
                    Body = body,
                    CreatedOnUtc = DateTime.UtcNow,
                    EmailAccountId = emailAccount.Id
                });

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

                return View(model);
            }

            model.DisplayCaptcha = _captchaSettings.Enabled && _captchaSettings.ShowOnContactUsPage;
            return View(model);
        }
        public ActionResult ContactVendor(int vendorId)
        {
            if (!_vendorSettings.AllowCustomersToContactVendors)
                return RedirectToRoute("HomePage");

            var vendor = _vendorService.GetVendorById(vendorId);
            if (vendor == null || !vendor.Active || vendor.Deleted)
                return RedirectToRoute("HomePage");

            var model = new ContactVendorModel
            {
                Email = _workContext.CurrentCustomer.Email,
                FullName = _workContext.CurrentCustomer.GetFullName(),
                SubjectEnabled = _commonSettings.SubjectFieldOnContactUsForm,
                DisplayCaptcha = _captchaSettings.Enabled && _captchaSettings.ShowOnContactUsPage,
                VendorId = vendor.Id,
                VendorName = vendor.GetLocalized(x => x.Name)
            };
            return View(model);
        }
 public void Should_not_have_error_when_fullName_is_specified()
 {
     var model = new ContactVendorModel();
     model.FullName = "John Smith";
     _validator.ShouldNotHaveValidationErrorFor(x => x.FullName, model);
 }
 public void Should_not_have_error_when_enquiry_is_specified()
 {
     var model = new ContactVendorModel();
     model.Enquiry = "please call me back";
     _validator.ShouldNotHaveValidationErrorFor(x => x.Enquiry, model);
 }
 public void Should_not_have_error_when_email_is_correct_format()
 {
     var model = new ContactVendorModel();
     model.Email = "*****@*****.**";
     _validator.ShouldNotHaveValidationErrorFor(x => x.Email, model);
 }