예제 #1
0
        public virtual async Task <IActionResult> ProductEmailAFriendSend(ProductEmailAFriendModel model, bool captchaValid)
        {
            var product = await _productService.GetProductById(model.ProductId);

            if (product == null || !product.Published || !_catalogSettings.EmailAFriendEnabled)
            {
                return(RedirectToRoute("HomePage"));
            }

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

            //check whether the current customer is guest and ia allowed to email a friend
            if (_workContext.CurrentCustomer.IsGuest() && !_catalogSettings.AllowAnonymousUsersToEmailAFriend)
            {
                ModelState.AddModelError("", _localizationService.GetResource("Products.EmailAFriend.OnlyRegisteredUsers"));
            }

            if (ModelState.IsValid)
            {
                //email
                await _productViewModelService.SendProductEmailAFriendMessage(product, model);

                model.ProductId     = product.Id;
                model.ProductName   = product.GetLocalized(x => x.Name, _workContext.WorkingLanguage.Id);
                model.ProductSeName = product.GetSeName(_workContext.WorkingLanguage.Id);

                model.SuccessfullySent = true;
                model.Result           = _localizationService.GetResource("Products.EmailAFriend.SuccessfullySent");

                return(View(model));
            }

            //If we got this far, something failed, redisplay form
            model.ProductId      = product.Id;
            model.ProductName    = product.GetLocalized(x => x.Name, _workContext.WorkingLanguage.Id);
            model.ProductSeName  = product.GetSeName(_workContext.WorkingLanguage.Id);
            model.DisplayCaptcha = _captchaSettings.Enabled && _captchaSettings.ShowOnEmailProductToFriendPage;
            return(View(model));
        }
예제 #2
0
        public ActionResult EmailAFriend(int id)
        {
            var product = _productService.GetProductById(id);

            if (product == null || product.Deleted || product.IsSystemProduct || !product.Published || !_catalogSettings.EmailAFriendEnabled)
            {
                return(HttpNotFound());
            }

            var model = new ProductEmailAFriendModel();

            model.ProductId                 = product.Id;
            model.ProductName               = product.GetLocalized(x => x.Name);
            model.ProductSeName             = product.GetSeName();
            model.YourEmailAddress          = _services.WorkContext.CurrentCustomer.Email;
            model.AllowChangedCustomerEmail = _catalogSettings.AllowDifferingEmailAddressForEmailAFriend;
            model.DisplayCaptcha            = _captchaSettings.Enabled && _captchaSettings.ShowOnEmailProductToFriendPage;
            return(View(model));
        }
예제 #3
0
        public async Task <IActionResult> EmailAFriendSend(ProductEmailAFriendModel model, int id, string captchaError)
        {
            var product = await _db.Products.FindByIdAsync(id, false);

            if (product == null || product.IsSystemProduct || !product.Published || !_catalogSettings.EmailAFriendEnabled)
            {
                return(NotFound());
            }

            if (_captchaSettings.ShowOnEmailProductToFriendPage && captchaError.HasValue())
            {
                ModelState.AddModelError("", captchaError);
            }

            var customer = Services.WorkContext.CurrentCustomer;

            // Check whether the current customer is guest and is allowed to email a friend.
            if (customer.IsGuest() && !_catalogSettings.AllowAnonymousUsersToEmailAFriend)
            {
                ModelState.AddModelError("", T("Products.EmailAFriend.OnlyRegisteredUsers"));
            }

            if (ModelState.IsValid)
            {
                //email
                await _messageFactory.Value.SendShareProductMessageAsync(
                    customer,
                    product,
                    model.YourEmailAddress,
                    model.FriendEmail,
                    HtmlUtils.ConvertPlainTextToHtml(model.PersonalMessage.HtmlEncode()));

                NotifySuccess(T("Products.EmailAFriend.SuccessfullySent"));

                return(RedirectToRoute("Product", new { SeName = await product.GetActiveSlugAsync() }));
            }

            // If we got this far something failed. Redisplay form.
            model = await PrepareEmailAFriendModelAsync(product);

            return(View(model));
        }
        /// <returns>A task that represents the asynchronous operation</returns>
        public virtual async Task <IActionResult> ProductEmailAFriendSend(ProductEmailAFriendModel model, bool captchaValid)
        {
            var product = await _productService.GetProductByIdAsync(model.ProductId);

            if (product == null || product.Deleted || !product.Published || !_catalogSettings.EmailAFriendEnabled)
            {
                return(RedirectToRoute("Homepage"));
            }

            //validate CAPTCHA
            if (_captchaSettings.Enabled && _captchaSettings.ShowOnEmailProductToFriendPage && !captchaValid)
            {
                ModelState.AddModelError("", await _localizationService.GetResourceAsync("Common.WrongCaptchaMessage"));
            }

            //check whether the current customer is guest and ia allowed to email a friend
            if (await _customerService.IsGuestAsync(await _workContext.GetCurrentCustomerAsync()) && !_catalogSettings.AllowAnonymousUsersToEmailAFriend)
            {
                ModelState.AddModelError("", await _localizationService.GetResourceAsync("Products.EmailAFriend.OnlyRegisteredUsers"));
            }

            if (ModelState.IsValid)
            {
                //email
                await _workflowMessageService.SendProductEmailAFriendMessageAsync(await _workContext.GetCurrentCustomerAsync(),
                                                                                  (await _workContext.GetWorkingLanguageAsync()).Id, product,
                                                                                  model.YourEmailAddress, model.FriendEmail,
                                                                                  Core.Html.HtmlHelper.FormatText(model.PersonalMessage, false, true, false, false, false, false));

                model = await _productModelFactory.PrepareProductEmailAFriendModelAsync(model, product, true);

                model.SuccessfullySent = true;
                model.Result           = await _localizationService.GetResourceAsync("Products.EmailAFriend.SuccessfullySent");

                return(View(model));
            }

            //If we got this far, something failed, redisplay form
            model = await _productModelFactory.PrepareProductEmailAFriendModelAsync(model, product, true);

            return(View(model));
        }
        public virtual ProductEmailAFriendModel PrepareProductEmailAFriendModel(ProductEmailAFriendModel model, Product product, bool excludeProperties)
        {
            if (model == null)
            {
                throw new ArgumentNullException("model");
            }

            if (product == null)
            {
                throw new ArgumentNullException("product");
            }

            model.ProductId      = product.Id;
            model.ProductName    = product.GetLocalized(x => x.Name);
            model.ProductSeName  = product.GetSeName();
            model.DisplayCaptcha = _captchaSettings.Enabled && _captchaSettings.ShowOnEmailProductToFriendPage;
            if (!excludeProperties)
            {
                model.YourEmailAddress = _workContext.CurrentCustomer.Email;
            }

            return(model);
        }