示例#1
0
        public virtual async Task <IActionResult> ContactUsSend(ContactUsModel model, IFormCollection form, bool captchaValid,
                                                                [FromServices] IContactAttributeFormatter contactAttributeFormatter)
        {
            //validate CAPTCHA
            if (_captchaSettings.Enabled && _captchaSettings.ShowOnContactUsPage && !captchaValid)
            {
                ModelState.AddModelError("", _captchaSettings.GetWrongCaptchaMessage(_localizationService));
            }

            //parse contact attributes
            var attributeXml = await _commonViewModelService.ParseContactAttributes(form);

            var contactAttributeWarnings = await _commonViewModelService.GetContactAttributesWarnings(attributeXml);

            if (contactAttributeWarnings.Any())
            {
                foreach (var item in contactAttributeWarnings)
                {
                    ModelState.AddModelError("", item);
                }
            }

            if (ModelState.IsValid)
            {
                model.ContactAttributeXml  = attributeXml;
                model.ContactAttributeInfo = await contactAttributeFormatter.FormatAttributes(attributeXml, _workContext.CurrentCustomer);

                model = await _commonViewModelService.SendContactUs(model);

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

                return(View(model));
            }

            model.DisplayCaptcha    = _captchaSettings.Enabled && _captchaSettings.ShowOnContactUsPage;
            model.ContactAttributes = await _commonViewModelService.PrepareContactAttributeModel(attributeXml);

            return(View(model));
        }