Пример #1
0
 protected virtual void PrepareNewsletterCategoriesModel(CampaignModel model)
 {
     if (model == null)
     {
         throw new ArgumentNullException("model");
     }
     model.AvailableNewsletterCategories = _newsletterCategoryService.GetAllNewsletterCategory().Select(ct => new SelectListItem()
     {
         Text = ct.Name, Value = ct.Id, Selected = model.NewsletterCategories.Contains(ct.Id)
     }).ToList();
     model.NewsletterCategories = new List <string>();
 }
        public IActionResult List()
        {
            if (!_permissionService.Authorize(StandardPermissionProvider.ManageNewsletterSubscribers))
            {
                return(AccessDeniedView());
            }

            var model = new NewsLetterSubscriptionListModel();

            //stores
            model.AvailableStores.Add(new SelectListItem {
                Text = _localizationService.GetResource("Admin.Common.All"), Value = " "
            });
            foreach (var s in _storeService.GetAllStores())
            {
                model.AvailableStores.Add(new SelectListItem {
                    Text = s.Name, Value = s.Id.ToString()
                });
            }

            //active
            model.ActiveList.Add(new SelectListItem
            {
                Value = " ",
                Text  = _localizationService.GetResource("Admin.Promotions.NewsLetterSubscriptions.List.SearchActive.All")
            });
            model.ActiveList.Add(new SelectListItem
            {
                Value = "1",
                Text  = _localizationService.GetResource("Admin.Promotions.NewsLetterSubscriptions.List.SearchActive.ActiveOnly")
            });
            model.ActiveList.Add(new SelectListItem
            {
                Value = "2",
                Text  = _localizationService.GetResource("Admin.Promotions.NewsLetterSubscriptions.List.SearchActive.NotActiveOnly")
            });

            foreach (var ca in _newsletterCategoryService.GetAllNewsletterCategory())
            {
                model.AvailableCategories.Add(new SelectListItem {
                    Text = ca.Name, Value = ca.Id.ToString()
                });
            }

            return(View(model));
        }
        public IActionResult List(DataSourceRequest command)
        {
            var newslettercategories = _newsletterCategoryService.GetAllNewsletterCategory();
            var gridModel            = new DataSourceResult
            {
                Data = newslettercategories.Select(x =>
                {
                    return(new {
                        Id = x.Id,
                        Name = x.Name,
                        Selected = x.Selected,
                        DisplayOrder = x.DisplayOrder
                    });
                }).OrderBy(x => x.DisplayOrder),
                Total = newslettercategories.Count
            };

            return(Json(gridModel));
        }
        public async Task <IActionResult> List()
        {
            var model = new NewsLetterSubscriptionListModel();

            var storeId = _workContext.CurrentCustomer.StaffStoreId;

            //stores
            model.AvailableStores.Add(new SelectListItem {
                Text = _translationService.GetResource("Admin.Common.All"), Value = " "
            });
            foreach (var s in (await _storeService.GetAllStores()).Where(x => x.Id == storeId || string.IsNullOrWhiteSpace(storeId)))
            {
                model.AvailableStores.Add(new SelectListItem {
                    Text = s.Shortcut, Value = s.Id.ToString()
                });
            }

            //active
            model.ActiveList.Add(new SelectListItem
            {
                Value = " ",
                Text  = _translationService.GetResource("admin.marketing.NewsLetterSubscriptions.List.SearchActive.All")
            });
            model.ActiveList.Add(new SelectListItem
            {
                Value = "1",
                Text  = _translationService.GetResource("admin.marketing.NewsLetterSubscriptions.List.SearchActive.ActiveOnly")
            });
            model.ActiveList.Add(new SelectListItem
            {
                Value = "2",
                Text  = _translationService.GetResource("admin.marketing.NewsLetterSubscriptions.List.SearchActive.NotActiveOnly")
            });

            foreach (var ca in await _newsletterCategoryService.GetAllNewsletterCategory())
            {
                model.AvailableCategories.Add(new SelectListItem {
                    Text = ca.Name, Value = ca.Id.ToString()
                });
            }

            return(View(model));
        }
        public async Task <IActionResult> List()
        {
            var model = new NewsLetterSubscriptionListModel();

            //stores
            model.AvailableStores.Add(new SelectListItem {
                Text = _localizationService.GetResource("Admin.Common.All"), Value = " "
            });
            foreach (var s in await _storeService.GetAllStores())
            {
                model.AvailableStores.Add(new SelectListItem {
                    Text = s.Name, Value = s.Id.ToString()
                });
            }

            //active
            model.ActiveList.Add(new SelectListItem
            {
                Value = " ",
                Text  = _localizationService.GetResource("Admin.Promotions.NewsLetterSubscriptions.List.SearchActive.All")
            });
            model.ActiveList.Add(new SelectListItem
            {
                Value = "1",
                Text  = _localizationService.GetResource("Admin.Promotions.NewsLetterSubscriptions.List.SearchActive.ActiveOnly")
            });
            model.ActiveList.Add(new SelectListItem
            {
                Value = "2",
                Text  = _localizationService.GetResource("Admin.Promotions.NewsLetterSubscriptions.List.SearchActive.NotActiveOnly")
            });

            foreach (var ca in await _newsletterCategoryService.GetAllNewsletterCategory())
            {
                model.AvailableCategories.Add(new SelectListItem {
                    Text = ca.Name, Value = ca.Id.ToString()
                });
            }

            return(View(model));
        }
Пример #6
0
        private async Task PrepareNewsletter(CustomerInfoModel model, GetInfo request)
        {
            //newsletter
            var newsletter = await _newsLetterSubscriptionService.GetNewsLetterSubscriptionByEmailAndStoreId(request.Customer.Email, request.Store.Id);

            //TODO - it is necessary ?
            //if (newsletter == null)
            //    newsletter = await _newsLetterSubscriptionService.GetNewsLetterSubscriptionByCustomerId(request.Customer.Id);

            model.Newsletter = newsletter != null && newsletter.Active;

            var categories = (await _newsletterCategoryService.GetAllNewsletterCategory()).ToList();

            categories.ForEach(x => model.NewsletterCategories.Add(new NewsletterSimpleCategory()
            {
                Id          = x.Id,
                Description = x.GetTranslation(y => y.Description, request.Language.Id),
                Name        = x.GetTranslation(y => y.Name, request.Language.Id),
                Selected    = newsletter == null ? false : newsletter.Categories.Contains(x.Id),
            }));
        }
        public IActionResult List(DataSourceRequest command)
        {
            if (!_permissionService.Authorize(StandardPermissionProvider.ManageNewsletterSubscribers))
            {
                return(AccessDeniedView());
            }

            var newslettercategories = _newsletterCategoryService.GetAllNewsletterCategory();
            var gridModel            = new DataSourceResult
            {
                Data = newslettercategories.Select(x =>
                {
                    return(new {
                        Id = x.Id,
                        Name = x.Name,
                        Selected = x.Selected
                    });
                }),
                Total = newslettercategories.Count
            };

            return(Json(gridModel));
        }
Пример #8
0
        public virtual async Task <CustomerInfoModel> PrepareInfoModel(CustomerInfoModel model, Customer customer,
                                                                       bool excludeProperties, string overrideCustomCustomerAttributesXml = "")
        {
            if (model == null)
            {
                throw new ArgumentNullException("model");
            }

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

            model.AllowCustomersToSetTimeZone = _dateTimeSettings.AllowCustomersToSetTimeZone;
            if (model.AllowCustomersToSetTimeZone)
            {
                foreach (var tzi in _dateTimeHelper.GetSystemTimeZones())
                {
                    model.AvailableTimeZones.Add(new SelectListItem {
                        Text = tzi.DisplayName, Value = tzi.Id, Selected = (excludeProperties ? tzi.Id == model.TimeZoneId : tzi.Id == _dateTimeHelper.CurrentTimeZone.Id)
                    });
                }
            }

            if (!excludeProperties)
            {
                model.VatNumber = await customer.GetAttribute <string>(_genericAttributeService, SystemCustomerAttributeNames.VatNumber);

                model.FirstName = await customer.GetAttribute <string>(_genericAttributeService, SystemCustomerAttributeNames.FirstName);

                model.LastName = await customer.GetAttribute <string>(_genericAttributeService, SystemCustomerAttributeNames.LastName);

                model.Gender = await customer.GetAttribute <string>(_genericAttributeService, SystemCustomerAttributeNames.Gender);

                var dateOfBirth = await customer.GetAttribute <DateTime?>(_genericAttributeService, SystemCustomerAttributeNames.DateOfBirth);

                if (dateOfBirth.HasValue)
                {
                    model.DateOfBirthDay   = dateOfBirth.Value.Day;
                    model.DateOfBirthMonth = dateOfBirth.Value.Month;
                    model.DateOfBirthYear  = dateOfBirth.Value.Year;
                }
                model.Company = await customer.GetAttribute <string>(_genericAttributeService, SystemCustomerAttributeNames.Company);

                model.StreetAddress = await customer.GetAttribute <string>(_genericAttributeService, SystemCustomerAttributeNames.StreetAddress);

                model.StreetAddress2 = await customer.GetAttribute <string>(_genericAttributeService, SystemCustomerAttributeNames.StreetAddress2);

                model.ZipPostalCode = await customer.GetAttribute <string>(_genericAttributeService, SystemCustomerAttributeNames.ZipPostalCode);

                model.City = await customer.GetAttribute <string>(_genericAttributeService, SystemCustomerAttributeNames.City);

                model.CountryId = await customer.GetAttribute <string>(_genericAttributeService, SystemCustomerAttributeNames.CountryId);

                model.StateProvinceId = await customer.GetAttribute <string>(_genericAttributeService, SystemCustomerAttributeNames.StateProvinceId);

                model.Phone = await customer.GetAttribute <string>(_genericAttributeService, SystemCustomerAttributeNames.Phone);

                model.Fax = await customer.GetAttribute <string>(_genericAttributeService, SystemCustomerAttributeNames.Fax);

                //newsletter
                var newsletter = await _newsLetterSubscriptionService.GetNewsLetterSubscriptionByEmailAndStoreId(customer.Email, _storeContext.CurrentStore.Id);

                if (newsletter == null)
                {
                    newsletter = await _newsLetterSubscriptionService.GetNewsLetterSubscriptionByCustomerId(customer.Id);
                }

                model.Newsletter = newsletter != null && newsletter.Active;

                var categories = (await _newsletterCategoryService.GetAllNewsletterCategory()).ToList();
                categories.ForEach(x => model.NewsletterCategories.Add(new NewsletterSimpleCategory()
                {
                    Id          = x.Id,
                    Description = x.GetLocalized(y => y.Description, _workContext.WorkingLanguage.Id),
                    Name        = x.GetLocalized(y => y.Name, _workContext.WorkingLanguage.Id),
                    Selected    = newsletter == null ? false : newsletter.Categories.Contains(x.Id),
                }));

                model.Signature = await customer.GetAttribute <string>(_genericAttributeService, SystemCustomerAttributeNames.Signature);

                model.Email    = customer.Email;
                model.Username = customer.Username;
            }
            else
            {
                if (_customerSettings.UsernamesEnabled && !_customerSettings.AllowUsersToChangeUsernames)
                {
                    model.Username = customer.Username;
                }
            }

            //countries and states
            if (_customerSettings.CountryEnabled)
            {
                model.AvailableCountries.Add(new SelectListItem {
                    Text = _localizationService.GetResource("Address.SelectCountry"), Value = ""
                });
                foreach (var c in await _countryService.GetAllCountries(_workContext.WorkingLanguage.Id))
                {
                    model.AvailableCountries.Add(new SelectListItem
                    {
                        Text     = c.GetLocalized(x => x.Name, _workContext.WorkingLanguage.Id),
                        Value    = c.Id.ToString(),
                        Selected = c.Id == model.CountryId
                    });
                }

                if (_customerSettings.StateProvinceEnabled)
                {
                    //states
                    var states = await _stateProvinceService.GetStateProvincesByCountryId(model.CountryId, _workContext.WorkingLanguage.Id);

                    if (states.Any())
                    {
                        model.AvailableStates.Add(new SelectListItem {
                            Text = _localizationService.GetResource("Address.SelectState"), Value = ""
                        });

                        foreach (var s in states)
                        {
                            model.AvailableStates.Add(new SelectListItem {
                                Text = s.GetLocalized(x => x.Name, _workContext.WorkingLanguage.Id), Value = s.Id.ToString(), Selected = (s.Id == model.StateProvinceId)
                            });
                        }
                    }
                    else
                    {
                        bool anyCountrySelected = model.AvailableCountries.Any(x => x.Selected);

                        model.AvailableStates.Add(new SelectListItem
                        {
                            Text  = _localizationService.GetResource(anyCountrySelected ? "Address.OtherNonUS" : "Address.SelectState"),
                            Value = ""
                        });
                    }
                }
            }
            model.DisplayVatNumber    = _taxSettings.EuVatEnabled;
            model.VatNumberStatusNote = ((VatNumberStatus)await customer.GetAttribute <int>(_genericAttributeService, SystemCustomerAttributeNames.VatNumberStatusId))
                                        .GetLocalizedEnum(_localizationService, _workContext);
            model.GenderEnabled                    = _customerSettings.GenderEnabled;
            model.DateOfBirthEnabled               = _customerSettings.DateOfBirthEnabled;
            model.DateOfBirthRequired              = _customerSettings.DateOfBirthRequired;
            model.CompanyEnabled                   = _customerSettings.CompanyEnabled;
            model.CompanyRequired                  = _customerSettings.CompanyRequired;
            model.StreetAddressEnabled             = _customerSettings.StreetAddressEnabled;
            model.StreetAddressRequired            = _customerSettings.StreetAddressRequired;
            model.StreetAddress2Enabled            = _customerSettings.StreetAddress2Enabled;
            model.StreetAddress2Required           = _customerSettings.StreetAddress2Required;
            model.ZipPostalCodeEnabled             = _customerSettings.ZipPostalCodeEnabled;
            model.ZipPostalCodeRequired            = _customerSettings.ZipPostalCodeRequired;
            model.CityEnabled                      = _customerSettings.CityEnabled;
            model.CityRequired                     = _customerSettings.CityRequired;
            model.CountryEnabled                   = _customerSettings.CountryEnabled;
            model.CountryRequired                  = _customerSettings.CountryRequired;
            model.StateProvinceEnabled             = _customerSettings.StateProvinceEnabled;
            model.StateProvinceRequired            = _customerSettings.StateProvinceRequired;
            model.PhoneEnabled                     = _customerSettings.PhoneEnabled;
            model.PhoneRequired                    = _customerSettings.PhoneRequired;
            model.FaxEnabled                       = _customerSettings.FaxEnabled;
            model.FaxRequired                      = _customerSettings.FaxRequired;
            model.NewsletterEnabled                = _customerSettings.NewsletterEnabled;
            model.UsernamesEnabled                 = _customerSettings.UsernamesEnabled;
            model.AllowUsersToChangeUsernames      = _customerSettings.AllowUsersToChangeUsernames;
            model.CheckUsernameAvailabilityEnabled = _customerSettings.CheckUsernameAvailabilityEnabled;
            model.SignatureEnabled                 = _forumSettings.ForumsEnabled && _forumSettings.SignaturesEnabled;

            //external authentication
            model.NumberOfExternalAuthenticationProviders = _externalAuthenticationService
                                                            .LoadActiveExternalAuthenticationMethods(_workContext.CurrentCustomer, _storeContext.CurrentStore.Id).Count;
            foreach (var ear in await _externalAuthenticationService.GetExternalIdentifiersFor(customer))
            {
                var authMethod = _externalAuthenticationService.LoadExternalAuthenticationMethodBySystemName(ear.ProviderSystemName);
                if (authMethod == null || !authMethod.IsMethodActive(_externalAuthenticationSettings))
                {
                    continue;
                }

                model.AssociatedExternalAuthRecords.Add(new CustomerInfoModel.AssociatedExternalAuthModel
                {
                    Id    = ear.Id,
                    Email = ear.Email,
                    ExternalIdentifier = ear.ExternalDisplayIdentifier,
                    AuthMethodName     = authMethod.GetLocalizedFriendlyName(_localizationService, _workContext.WorkingLanguage.Id)
                });
            }

            //custom customer attributes
            var customAttributes = await PrepareCustomAttributes(customer, overrideCustomCustomerAttributesXml);

            foreach (var attribute in customAttributes)
            {
                model.CustomerAttributes.Add(attribute);
            }

            return(model);
        }