Exemplo n.º 1
0
        public ActionResult Index()
        {
            var model = new SupportModel();

            var customer = _workContext.CurrentCustomer;

            if (!customer.IsGuest())
            {
                var address = customer.BillingAddress ?? customer.ShippingAddress;

                if (address != null)
                {
                    model.Email = address.Email;
                    model.FirstName = address.FirstName;
                    model.LastName = address.LastName;
                    model.City = address.City;
                    model.AddressLine1 = address.Address1;
                    model.AddressLine2 = address.Address2;
                    model.Phone = address.PhoneNumber;
                    model.CountryId = address.CountryId;
                    model.PostalCode = address.ZipPostalCode;

                    if (address.StateProvince != null)
                    {
                        model.StateProvince = address.StateProvince.Name;
                    }
                }
            };

            FillCountries(model);
            FillCategories(model);
            FillManufacturers(model);

            return View("~/Plugins/AtrendUsa.Plugin.Misc.Support/Views/Index.cshtml", model);
        }
Exemplo n.º 2
0
        private List<Token> GetSupportModelTokens(SupportModel model)
        {
            var tokens = new List<Token>();

            tokens.Add(new Token("SupportModel.FirstName", model.FirstName));
            tokens.Add(new Token("SupportModel.LastName", model.LastName));
            tokens.Add(new Token("SupportModel.Email", model.Email));
            tokens.Add(new Token("SupportModel.AddressLine1", model.AddressLine1));
            tokens.Add(new Token("SupportModel.AddressLine2", model.AddressLine2));
            tokens.Add(new Token("SupportModel.City", model.City));
            tokens.Add(new Token("SupportModel.DatePurchased", model.DatePurchased));
            tokens.Add(new Token("SupportModel.Dealer", model.Dealer));
            tokens.Add(new Token("SupportModel.ModelNumber", model.ModelNumber));
            tokens.Add(new Token("SupportModel.Phone", model.Phone));
            tokens.Add(new Token("SupportModel.PostalCode", model.PostalCode));
            tokens.Add(new Token("SupportModel.Problem", model.Problem));
            tokens.Add(new Token("SupportModel.SerialNumber", model.SerialNumber));
            tokens.Add(new Token("SupportModel.StateProvince", model.StateProvince));
            tokens.Add(new Token("SupportModel.UnderWarranty", model.IsUnderWarranty ? "Yes" : "No"));

            if (model.CountryId.HasValue)
            {
                tokens.Add(new Token("SupportModel.Country", _countryService.GetCountryById(model.CountryId.Value).Name));
            }

            if (model.ManufacturerId.HasValue)
            {
                tokens.Add(new Token("SupportModel.Brand", _manufacturerService.GetManufacturerById(model.ManufacturerId.Value).Name));
            }

            if (model.CategoryId.HasValue)
            {
                tokens.Add(new Token("SupportModel.Category", _categoryService.GetCategoryById(model.CategoryId.Value).Name));
            }

            return tokens;
        }
Exemplo n.º 3
0
        private void FillManufacturers(SupportModel model)
        {
            model.AvailableManufacturers.Add(new SelectListItem() { Text = _localizationService.GetResource("AtrendUsa.Plugin.Misc.Support.SelectManufacturer"), Value = "0" });

            foreach (var c in _manufacturerService.GetAllManufacturers())
            {
                model.AvailableManufacturers.Add(new SelectListItem() { Text = c.Name, Value = c.Id.ToString() });
            }
        }
Exemplo n.º 4
0
        public ActionResult Index(SupportModel model)
        {
            if (ModelState.IsValid)
            {
                string email = model.Email.Trim();
                string fullName = string.Format("{0} {1}", model.FirstName, model.LastName);
                string subject = _localizationService.GetResource("AtrendUsa.Plugin.Misc.Support.EmailSubject") + " - " + fullName;

                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 = email;
                string fromName = fullName;

                string body = _tokenizer.Replace(SupportMessageTemplate, GetSupportModelTokens(model), true);

                _queuedEmailService.InsertQueuedEmail(new QueuedEmail()
                {
                    From = from,
                    FromName = fromName,
                    To = emailAccount.Email,
                    ToName = emailAccount.DisplayName,
                    ReplyTo = email,
                    ReplyToName = fullName,
                    Priority = 5,
                    Subject = subject,
                    Body = body,
                    CreatedOnUtc = DateTime.UtcNow,
                    EmailAccountId = emailAccount.Id
                });

                model.SuccessfullySent = true;
                model.Result = _localizationService.GetResource("AtrendUsa.Plugin.Misc.Support.RequestSuccessfulSent");

                var fullMessage = Nop.Core.Html.HtmlHelper.FormatText(body, true, false, false, false, false, false);
                _logger.InsertLog(LogLevel.Information, subject, fullMessage);

                return View("~/Plugins/AtrendUsa.Plugin.Misc.Support/Views/Index.cshtml", model);
            }

            FillCountries(model);
            FillCategories(model);
            FillManufacturers(model);

            return View("~/Plugins/AtrendUsa.Plugin.Misc.Support/Views/Index.cshtml", model);
        }
Exemplo n.º 5
0
        private void FillCategories(SupportModel model)
        {
            model.AvailableCategories.Add(new SelectListItem() { Text = _localizationService.GetResource("AtrendUsa.Plugin.Misc.Support.SelectCategory"), Value = "0" });

            foreach (var c in _categoryService.GetAllCategories())
            {
                model.AvailableCategories.Add(new SelectListItem() { Text = c.Name, Value = c.Id.ToString() });
            }
        }