Beispiel #1
0
        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_email_is_correct_format()
        {
            var model = new ContactVendorModel();

            model.Email = "*****@*****.**";
            _validator.ShouldNotHaveValidationErrorFor(x => x.Email, model);
        }
Beispiel #3
0
        /// <summary>
        /// Prepare the contact vendor model
        /// </summary>
        /// <param name="model">Contact vendor model</param>
        /// <param name="vendor">Vendor</param>
        /// <param name="excludeProperties">Whether to exclude populating of model properties from the entity</param>
        /// <returns>Contact vendor model</returns>
        public virtual ContactVendorModel PrepareContactVendorModel(ContactVendorModel model, Vendor vendor, bool excludeProperties)
        {
            if (model == null)
            {
                throw new ArgumentNullException(nameof(model));
            }

            if (vendor == null)
            {
                throw new ArgumentNullException(nameof(vendor));
            }

            if (!excludeProperties)
            {
                model.Email    = _workContext.CurrentCustomer.Email;
                model.FullName = _customerService.GetCustomerFullName(_workContext.CurrentCustomer);
            }

            model.SubjectEnabled = _commonSettings.SubjectFieldOnContactUsForm;
            model.DisplayCaptcha = _captchaSettings.Enabled && _captchaSettings.ShowOnContactUsPage;
            model.VendorId       = vendor.Id;
            model.VendorName     = _localizationService.GetLocalized(vendor, x => x.Name);

            return(model);
        }
Beispiel #4
0
        public virtual IActionResult ContactVendorSend(ContactVendorModel model, bool captchaValid)
        {
            if (!_vendorSettings.AllowCustomersToContactVendors)
            {
                return(RedirectToRoute("HomePage"));
            }

            var vendor = EngineContext.Current.Resolve <IVendorService>().GetVendorById(model.VendorId);

            if (vendor == null || !vendor.Active || vendor.Deleted)
            {
                return(RedirectToRoute("HomePage"));
            }

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

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

            if (ModelState.IsValid)
            {
                model = _commonViewModelService.SendContactVendor(model, vendor);
                return(View(model));
            }

            model.DisplayCaptcha = _captchaSettings.Enabled && _captchaSettings.ShowOnContactUsPage;
            return(View(model));
        }
        public void ShouldHaveErrorWhenEmailIsWrongFormat()
        {
            var model = new ContactVendorModel
            {
                Email = "adminexample.com"
            };

            _validator.TestValidate(model).ShouldHaveValidationErrorFor(x => x.Email);
        }
        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);
        }
Beispiel #8
0
        public void ShouldNotHaveErrorWhenFullnameIsSpecified()
        {
            var model = new ContactVendorModel
            {
                FullName = "John Smith"
            };

            _validator.ShouldNotHaveValidationErrorFor(x => x.FullName, model);
        }
Beispiel #9
0
        public void ShouldNotHaveErrorWhenEmailIsCorrectFormat()
        {
            var model = new ContactVendorModel
            {
                Email = "*****@*****.**"
            };

            _validator.ShouldNotHaveValidationErrorFor(x => x.Email, model);
        }
        public void Should_not_have_error_when_enquiry_is_specified()
        {
            var model = new ContactVendorModel
            {
                Enquiry = "please call me back"
            };

            _validator.ShouldNotHaveValidationErrorFor(x => x.Enquiry, model);
        }
        public void Should_not_have_error_when_fullName_is_specified()
        {
            var model = new ContactVendorModel
            {
                FullName = "John Smith"
            };

            _validator.ShouldNotHaveValidationErrorFor(x => x.FullName, model);
        }
        public void Should_have_error_when_email_is_wrong_format()
        {
            var model = new ContactVendorModel
            {
                Email = "adminexample.com"
            };

            _validator.ShouldHaveValidationErrorFor(x => x.Email, model);
        }
Beispiel #13
0
        public void ShouldNotHaveErrorWhenEnquiryIsSpecified()
        {
            var model = new ContactVendorModel
            {
                Enquiry = "please call me back"
            };

            _validator.ShouldNotHaveValidationErrorFor(x => x.Enquiry, model);
        }
Beispiel #14
0
        public void ShouldHaveErrorWhenEnquiryIsNullOrEmpty()
        {
            var model = new ContactVendorModel
            {
                Enquiry = null
            };

            _validator.ShouldHaveValidationErrorFor(x => x.Enquiry, model);
            model.Enquiry = string.Empty;
            _validator.ShouldHaveValidationErrorFor(x => x.Enquiry, model);
        }
        public virtual ContactVendorModel SendContactVendor(ContactVendorModel model, Vendor vendor)
        {
            string subject = _commonSettings.SubjectFieldOnContactUsForm ? model.Subject : null;
            string body    = Core.Html.HtmlHelper.FormatText(model.Enquiry, false, true, false, false, false, false);

            _workflowMessageService.SendContactVendorMessage(_workContext.CurrentCustomer, vendor, _workContext.WorkingLanguage.Id, model.Email.Trim(), model.FullName, subject, body);

            model.SuccessfullySent = true;
            model.Result           = _localizationService.GetResource("ContactVendor.YourEnquiryHasBeenSent");
            return(model);
        }
        public void ShouldHaveErrorWhenEmailIsNullOrEmpty()
        {
            var model = new ContactVendorModel
            {
                Email = null
            };

            _validator.TestValidate(model).ShouldHaveValidationErrorFor(x => x.Email);
            model.Email = string.Empty;
            _validator.TestValidate(model).ShouldHaveValidationErrorFor(x => x.Email);
        }
        public void Should_have_error_when_email_is_null_or_empty()
        {
            var model = new ContactVendorModel
            {
                Email = null
            };

            _validator.ShouldHaveValidationErrorFor(x => x.Email, model);
            model.Email = "";
            _validator.ShouldHaveValidationErrorFor(x => x.Email, model);
        }
Beispiel #18
0
        public void ShouldHaveErrorWhenFullnameIsNullOrEmpty()
        {
            var model = new ContactVendorModel
            {
                FullName = null
            };

            _validator.ShouldHaveValidationErrorFor(x => x.FullName, model);
            model.FullName = string.Empty;
            _validator.ShouldHaveValidationErrorFor(x => x.FullName, model);
        }
        public virtual ContactVendorModel PrepareContactVendor(Vendor vendor)
        {
            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(model);
        }
Beispiel #20
0
        public virtual IActionResult 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();

            model = _commonModelFactory.PrepareContactVendorModel(model, vendor, false);
            return(View(model));
        }
Beispiel #21
0
        public virtual IActionResult 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.WrongCaptchaMessage"));
            }

            model = _commonModelFactory.PrepareContactVendorModel(model, vendor, true);

            if (ModelState.IsValid)
            {
                var subject = _commonSettings.SubjectFieldOnContactUsForm ? model.Subject : null;
                var body    = Core.Html.HtmlHelper.FormatText(model.Enquiry, false, true, false, false, false, false);

                _workflowMessageService.SendContactVendorMessage(vendor, _workContext.WorkingLanguage.Id,
                                                                 model.Email.Trim(), model.FullName, subject, body);

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

                return(View(model));
            }

            return(View(model));
        }
        public async Task CanPrepareContactVendorModel()
        {
            var model = new ContactVendorModel();

            model = await _commonModelFactory.PrepareContactVendorModelAsync(model, _vendor, true);

            model.Email.Should().BeNullOrEmpty();
            model.FullName.Should().BeNullOrEmpty();

            model.SubjectEnabled = _commonSettings.SubjectFieldOnContactUsForm;
            model.DisplayCaptcha.Should().BeFalse();
            model.VendorId.Should().Be(_vendor.Id);
            model.VendorName.Should().Be(_vendor.Name);

            model = await _commonModelFactory.PrepareContactVendorModelAsync(model, _vendor, false);

            model.Email.Should().Be(NopTestsDefaults.AdminEmail);
            model.FullName.Should().Be("John Smith");

            model.SubjectEnabled = _commonSettings.SubjectFieldOnContactUsForm;
            model.DisplayCaptcha.Should().BeFalse();
            model.VendorId.Should().Be(_vendor.Id);
            model.VendorName.Should().Be(_vendor.Name);
        }
Beispiel #23
0
        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  = 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 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 = 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(),
                DisplayCaptcha = _captchaSettings.Enabled && _captchaSettings.ShowOnContactUsPage,
                VendorId = vendor.Id,
                VendorName = vendor.GetLocalized(x => x.Name)
            };
            return View(model);
        }