public virtual async Task <IActionResult> ContactVendorSend(ContactVendorModel model, bool captchaValid, [FromServices] IVendorService vendorService)
        {
            if (!_vendorSettings.AllowCustomersToContactVendors)
            {
                return(RedirectToRoute("HomePage"));
            }

            var vendor = await vendorService.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, _workContext.WorkingLanguage.Id);

            if (ModelState.IsValid)
            {
                model = await _commonViewModelService.SendContactVendor(model, vendor);

                return(View(model));
            }

            model.DisplayCaptcha = _captchaSettings.Enabled && _captchaSettings.ShowOnContactUsPage;
            return(View(model));
        }
示例#2
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));
        }