Exemplo n.º 1
0
        public ActionResult List()
        {
            if (!_permissionService.Authorize(StandardPermissionProvider.ManageNewsletterSubscribers))
            {
                return(AccessDeniedView());
            }

            var newsletterSubscriptions = _newsLetterSubscriptionService.GetAllNewsLetterSubscriptions(String.Empty, 0, _adminAreaSettings.GridPageSize, true);
            var model = new NewsLetterSubscriptionListModel();

            PrepareNewsLetterSubscriptionListModel(model);

            model.NewsLetterSubscriptions = new GridModel <NewsLetterSubscriptionModel>
            {
                Data = newsletterSubscriptions.Select(x =>
                {
                    var m     = x.ToModel();
                    var store = _storeService.GetStoreById(x.StoreId);

                    m.CreatedOn = _dateTimeHelper.ConvertToUserTime(x.CreatedOnUtc, DateTimeKind.Utc);
                    m.StoreName = store != null ? store.Name : "".NaIfEmpty();

                    return(m);
                }),
                Total = newsletterSubscriptions.TotalCount
            };
            return(View(model));
        }
        public ActionResult SubscriptionList(GridCommand command, NewsLetterSubscriptionListModel model)
        {
            if (!_permissionService.Authorize(StandardPermissionProvider.ManageNewsletterSubscribers))
            {
                return(AccessDeniedView());
            }

            var newsletterSubscriptions = _newsLetterSubscriptionService.GetAllNewsLetterSubscriptions(model.SearchEmail,
                                                                                                       command.Page - 1, command.PageSize, true);

            var gridModel = new GridModel <NewsLetterSubscriptionModel>
            {
                Data = newsletterSubscriptions.Select(x =>
                {
                    var m       = x.ToModel();
                    m.CreatedOn = _dateTimeHelper.ConvertToUserTime(x.CreatedOnUtc, DateTimeKind.Utc);
                    return(m);
                }),
                Total = newsletterSubscriptions.TotalCount
            };

            return(new JsonResult
            {
                Data = gridModel
            });
        }
Exemplo n.º 3
0
        public ActionResult SubscriptionList(GridCommand command, NewsLetterSubscriptionListModel model)
        {
            var gridModel = new GridModel <NewsLetterSubscriptionModel>();

            if (_permissionService.Authorize(StandardPermissionProvider.ManageNewsletterSubscribers))
            {
                var newsletterSubscriptions = _newsLetterSubscriptionService.GetAllNewsLetterSubscriptions(
                    model.SearchEmail, command.Page - 1, command.PageSize, true, model.StoreId);

                gridModel.Data = newsletterSubscriptions.Select(x =>
                {
                    var m     = x.ToModel();
                    var store = _storeService.GetStoreById(x.StoreId);

                    m.CreatedOn = _dateTimeHelper.ConvertToUserTime(x.CreatedOnUtc, DateTimeKind.Utc);
                    m.StoreName = store != null ? store.Name : "".NaIfEmpty();

                    return(m);
                });

                gridModel.Total = newsletterSubscriptions.TotalCount;
            }
            else
            {
                gridModel.Data = Enumerable.Empty <NewsLetterSubscriptionModel>();

                NotifyAccessDenied();
            }

            return(new JsonResult
            {
                Data = gridModel
            });
        }
        public ActionResult SubscriptionUpdate(NewsLetterSubscriptionModel model, GridCommand command)
        {
            if (!_permissionService.Authorize(StandardPermissionProvider.ManageNewsletterSubscribers))
            {
                return(AccessDeniedView());
            }

            if (!ModelState.IsValid)
            {
                //display the first model error
                var modelStateErrors = this.ModelState.Values.SelectMany(x => x.Errors).Select(x => x.ErrorMessage);
                return(Content(modelStateErrors.FirstOrDefault()));
            }

            var subscription = _newsLetterSubscriptionService.GetNewsLetterSubscriptionById(model.Id);

            subscription.Email  = model.Email;
            subscription.Active = model.Active;

            _newsLetterSubscriptionService.UpdateNewsLetterSubscription(subscription);

            var listModel = new NewsLetterSubscriptionListModel();

            PrepareNewsLetterSubscriptionListModel(listModel);

            return(SubscriptionList(command, listModel));
        }
        private void PrepareNewsLetterSubscriptionListModel(NewsLetterSubscriptionListModel model)
        {
            var stores = Services.StoreService.GetAllStores().ToList();

            model.AvailableStores = stores.ToSelectListItems();
            model.GridPageSize    = _adminAreaSettings.GridPageSize;
        }
        public virtual ActionResult List()
        {
            if (!_permissionService.Authorize(StandardPermissionProvider.ManageNewsletterSubscribers))
            {
                return(AccessDeniedView());
            }

            var model = new NewsLetterSubscriptionListModel();

            #region Extensions by QuanNH
            //stores
            var _workContext = Nop.Core.Infrastructure.EngineContext.Current.Resolve <IWorkContext>();
            var AllStores    = _storeService.GetAllStoresByEntityName(_workContext.CurrentCustomer.Id, "Stores");
            if (AllStores.Count <= 0)
            {
                AllStores = _storeService.GetAllStores();
                model.AvailableStores.Add(new SelectListItem {
                    Text = _localizationService.GetResource("Admin.Common.All"), Value = "0"
                });
            }

            foreach (var s in AllStores)
            {
                model.AvailableStores.Add(new SelectListItem {
                    Text = s.Name, Value = s.Id.ToString()
                });
            }

            #endregion

            //active
            model.ActiveList.Add(new SelectListItem
            {
                Value = "0",
                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")
            });

            //customer roles
            model.AvailableCustomerRoles.Add(new SelectListItem {
                Text = _localizationService.GetResource("Admin.Common.All"), Value = "0"
            });
            foreach (var cr in _customerService.GetAllCustomerRoles(true))
            {
                model.AvailableCustomerRoles.Add(new SelectListItem {
                    Text = cr.Name, Value = cr.Id.ToString()
                });
            }

            return(View(model));
        }
        public ActionResult SubscriptionList(GridCommand command, NewsLetterSubscriptionListModel model)
        {
            var gridModel = new GridModel <NewsLetterSubscriptionModel>();
            var allStores = Services.StoreService.GetAllStores().ToDictionary(x => x.Id);
            var newsletterSubscriptions = _newsLetterSubscriptionService.GetAllNewsLetterSubscriptions(
                model.SearchEmail,
                command.Page - 1,
                command.PageSize,
                true,
                model.StoreId != 0 ? new int[] { model.StoreId } : null);

            gridModel.Data = newsletterSubscriptions.Select(x =>
            {
                var m = x.Subscription.ToModel();
                allStores.TryGetValue(x.Subscription.StoreId, out var store);

                m.CreatedOn = _dateTimeHelper.ConvertToUserTime(x.Subscription.CreatedOnUtc, DateTimeKind.Utc);
                m.StoreName = store?.Name.NaIfEmpty();

                return(m);
            });

            gridModel.Total = newsletterSubscriptions.TotalCount;

            return(new JsonResult
            {
                Data = gridModel
            });
        }
        public ActionResult List()
        {
            var newsletterSubscriptions = _newsLetterSubscriptionService.GetAllNewsLetterSubscriptions(string.Empty, 0, _adminAreaSettings.GridPageSize, true);

            var allStores = Services.StoreService.GetAllStores().ToDictionary(x => x.Id);
            var model     = new NewsLetterSubscriptionListModel();

            PrepareNewsLetterSubscriptionListModel(model);

            model.NewsLetterSubscriptions = new GridModel <NewsLetterSubscriptionModel>
            {
                Data = newsletterSubscriptions.Select(x =>
                {
                    var m = x.Subscription.ToModel();
                    allStores.TryGetValue(x.Subscription.StoreId, out var store);

                    m.CreatedOn = _dateTimeHelper.ConvertToUserTime(x.Subscription.CreatedOnUtc, DateTimeKind.Utc);
                    m.StoreName = store?.Name.NaIfEmpty();

                    return(m);
                }),
                Total = newsletterSubscriptions.TotalCount
            };

            return(View(model));
        }
        public IActionResult SubscriptionList(DataSourceRequest command, NewsLetterSubscriptionListModel model, string[] searchCategoryIds)
        {
            bool?isActive = null;

            if (model.ActiveId == 1)
            {
                isActive = true;
            }
            else if (model.ActiveId == 2)
            {
                isActive = false;
            }

            var newsletterSubscriptions = _newsLetterSubscriptionService.GetAllNewsLetterSubscriptions(model.SearchEmail,
                                                                                                       model.StoreId, isActive, searchCategoryIds, command.Page - 1, command.PageSize);

            var gridModel = new DataSourceResult
            {
                Data = newsletterSubscriptions.Select(x =>
                {
                    var m        = x.ToModel();
                    var store    = _storeService.GetStoreById(x.StoreId);
                    m.StoreName  = store != null ? store.Name : "Unknown store";
                    m.CreatedOn  = _dateTimeHelper.ConvertToUserTime(x.CreatedOnUtc, DateTimeKind.Utc).ToLongTimeString();
                    m.Categories = GetCategoryNames(x.Categories.ToList());
                    return(m);
                }),
                Total = newsletterSubscriptions.TotalCount
            };

            return(Json(gridModel));
        }
        public virtual ActionResult ExportCsv(NewsLetterSubscriptionListModel model)
        {
            if (!_permissionService.Authorize(StandardPermissionProvider.ManageNewsletterSubscribers))
            {
                return(AccessDeniedView());
            }

            bool?isActive = null;

            if (model.ActiveId == 1)
            {
                isActive = true;
            }
            else if (model.ActiveId == 2)
            {
                isActive = false;
            }

            var startDateValue = (model.StartDate == null) ? null
                : (DateTime?)_dateTimeHelper.ConvertToUtcTime(model.StartDate.Value, _dateTimeHelper.CurrentTimeZone);
            var endDateValue = (model.EndDate == null) ? null
                : (DateTime?)_dateTimeHelper.ConvertToUtcTime(model.EndDate.Value, _dateTimeHelper.CurrentTimeZone).AddDays(1);

            var subscriptions = _newsLetterSubscriptionService.GetAllNewsLetterSubscriptions(model.SearchEmail,
                                                                                             startDateValue, endDateValue, model.StoreId, isActive, model.CustomerRoleId);

            string result = _exportManager.ExportNewsletterSubscribersToTxt(subscriptions);

            string fileName = String.Format("newsletter_emails_{0}_{1}.txt", DateTime.Now.ToString("yyyy-MM-dd-HH-mm-ss"), CommonHelper.GenerateRandomDigitCode(4));

            return(File(Encoding.UTF8.GetBytes(result), MimeTypes.TextCsv, fileName));
        }
Exemplo n.º 11
0
        public async Task <IActionResult> ExportCsv(NewsLetterSubscriptionListModel model, string[] searchCategoryIds)
        {
            bool?isActive = null;

            if (model.ActiveId == 1)
            {
                isActive = true;
            }
            else if (model.ActiveId == 2)
            {
                isActive = false;
            }

            if (_workContext.CurrentCustomer.IsStaff())
            {
                model.StoreId = _workContext.CurrentCustomer.StaffStoreId;
            }

            var subscriptions = await _newsLetterSubscriptionService.GetAllNewsLetterSubscriptions(model.SearchEmail,
                                                                                                   model.StoreId, isActive, searchCategoryIds);

            string result = _exportManager.ExportNewsletterSubscribersToTxt(subscriptions);

            string fileName = String.Format("newsletter_emails_{0}_{1}.txt", DateTime.Now.ToString("yyyy-MM-dd-HH-mm-ss"), CommonHelper.GenerateRandomDigitCode(4));

            return(File(Encoding.UTF8.GetBytes(result), "text/csv", fileName));
        }
Exemplo n.º 12
0
        public ActionResult SubscriptionList(GridCommand command, NewsLetterSubscriptionListModel model)
        {
            var gridModel = new GridModel <NewsLetterSubscriptionModel>();

            var newsletterSubscriptions = _newsLetterSubscriptionService.GetAllNewsLetterSubscriptions(
                model.SearchEmail, command.Page - 1, command.PageSize, true, model.StoreId);

            gridModel.Data = newsletterSubscriptions.Select(x =>
            {
                var m     = x.ToModel();
                var store = _storeService.GetStoreById(x.StoreId);

                m.CreatedOn = _dateTimeHelper.ConvertToUserTime(x.CreatedOnUtc, DateTimeKind.Utc);
                m.StoreName = store != null ? store.Name : "".NaIfEmpty();

                return(m);
            });

            gridModel.Total = newsletterSubscriptions.TotalCount;

            return(new JsonResult
            {
                Data = gridModel
            });
        }
        public ActionResult ExportCsv(NewsLetterSubscriptionListModel model)
        {
            if (!_permissionService.Authorize(StandardPermissionProvider.ManageNewsletterSubscribers))
            {
                return(AccessDeniedView());
            }

            string fileName = String.Format("newsletter_emails_{0}_{1}.txt", DateTime.Now.ToString("yyyy-MM-dd-HH-mm-ss"), CommonHelper.GenerateRandomDigitCode(4));

            var sb = new StringBuilder();
            var newsLetterSubscriptions = _newsLetterSubscriptionService.GetAllNewsLetterSubscriptions(model.SearchEmail, 0, int.MaxValue, true);

            if (newsLetterSubscriptions.Count == 0)
            {
                throw new NopException("No emails to export");
            }
            for (int i = 0; i < newsLetterSubscriptions.Count; i++)
            {
                var subscription = newsLetterSubscriptions[i];
                sb.Append(subscription.Email);
                sb.Append("\t");
                sb.Append(subscription.Active);
                sb.Append("\r\n");  //new line
            }
            string result = sb.ToString();

            return(File(Encoding.UTF8.GetBytes(result), "text/csv", fileName));
        }
Exemplo n.º 14
0
        public ActionResult SubscriptionList(DataSourceRequest command, NewsLetterSubscriptionListModel model)
        {
            if (!_permissionService.Authorize(StandardPermissionProvider.ManageNewsletterSubscribers))
            {
                return(AccessDeniedView());
            }

            var newsletterSubscriptions = _newsLetterSubscriptionService.GetAllNewsLetterSubscriptions(model.SearchEmail,
                                                                                                       model.StoreId, command.Page - 1, command.PageSize, true);

            var gridModel = new DataSourceResult
            {
                Data = newsletterSubscriptions.Select(x =>
                {
                    var m       = x.ToModel();
                    var store   = _storeService.GetStoreById(x.StoreId);
                    m.StoreName = store != null ? store.Name : "Unknown store";
                    m.CreatedOn = _dateTimeHelper.ConvertToUserTime(x.CreatedOnUtc, DateTimeKind.Utc);
                    return(m);
                }),
                Total = newsletterSubscriptions.TotalCount
            };

            return(Json(gridModel));
        }
Exemplo n.º 15
0
        public ActionResult ExportCsv(NewsLetterSubscriptionListModel model)
        {
            if (!_permissionService.Authorize(StandardPermissionProvider.ManageNewsletterSubscribers))
            {
                return(AccessDeniedView());
            }

            string fileName = String.Format("newsletter_emails_{0}_{1}.txt", DateTime.Now.ToString("yyyy-MM-dd-HH-mm-ss"), CommonHelper.GenerateRandomDigitCode(4));

            var sb = new StringBuilder();
            var newsLetterSubscriptions = _newsLetterSubscriptionService.GetAllNewsLetterSubscriptions(model.SearchEmail,
                                                                                                       model.StoreId, 0, int.MaxValue, true);

            foreach (var subscription in newsLetterSubscriptions)
            {
                sb.Append(subscription.Email);
                sb.Append(",");
                sb.Append(subscription.Active);
                sb.Append(",");
                sb.Append(subscription.StoreId);
                sb.Append(Environment.NewLine);  //new line
            }
            string result = sb.ToString();

            return(File(Encoding.UTF8.GetBytes(result), "text/csv", fileName));
        }
Exemplo n.º 16
0
        public ActionResult ExportCsv(NewsLetterSubscriptionListModel model)
        {
            if (!_permissionService.Authorize(StandardPermissionProvider.ManageNewsletterSubscribers))
            {
                return(AccessDeniedView());
            }

            bool?isActive = null;

            if (model.ActiveId == 1)
            {
                isActive = true;
            }
            else if (model.ActiveId == 2)
            {
                isActive = false;
            }

            var subscriptions = _newsLetterSubscriptionService.GetAllNewsLetterSubscriptions(model.SearchEmail,
                                                                                             model.StoreId, isActive);

            string result = _exportManager.ExportNewsletterSubscribersToTxt(subscriptions);

            string fileName = String.Format("newsletter_emails_{0}_{1}.txt", DateTime.Now.ToString("yyyy-MM-dd-HH-mm-ss"), CommonHelper.GenerateRandomDigitCode(4));

            return(File(Encoding.UTF8.GetBytes(result), "text/csv", fileName));
        }
        public ActionResult List()
        {
            if (!_permissionService.Authorize(StandardPermissionProvider.ManageNewsletterSubscribers))
            {
                return(AccessDeniedView());
            }

            var model = new NewsLetterSubscriptionListModel();

            return(View(model));
        }
        private void PrepareNewsLetterSubscriptionListModel(NewsLetterSubscriptionListModel model)
        {
            var stores = _storeService.GetAllStores().ToList();

            model.GridPageSize = _adminAreaSettings.GridPageSize;

            model.AvailableStores.Add(new SelectListItem()
            {
                Text = _localizationService.GetResource("Admin.Common.All"), Value = "0"
            });
            model.AvailableStores.AddRange(stores.ToSelectListItems());
        }
        public ActionResult SubscriptionDelete(int id, GridCommand command)
        {
            var subscription = _newsLetterSubscriptionService.GetNewsLetterSubscriptionById(id);

            _newsLetterSubscriptionService.DeleteNewsLetterSubscription(subscription);

            var listModel = new NewsLetterSubscriptionListModel();

            PrepareNewsLetterSubscriptionListModel(listModel);

            return(SubscriptionList(command, listModel));
        }
Exemplo n.º 20
0
        public virtual ActionResult SubscriptionList(DataSourceRequest command, NewsLetterSubscriptionListModel model)
        {
            if (!_permissionService.Authorize(StandardPermissionProvider.ManageNewsletterSubscribers))
            {
                return(AccessDeniedKendoGridJson());
            }

            bool?isActive = null;

            if (model.ActiveId == 1)
            {
                isActive = true;
            }
            else if (model.ActiveId == 2)
            {
                isActive = false;
            }

            var startDateValue = (model.StartDate == null) ? null
                : (DateTime?)_dateTimeHelper.ConvertToUtcTime(model.StartDate.Value, _dateTimeHelper.CurrentTimeZone);
            var endDateValue = (model.EndDate == null) ? null
                : (DateTime?)_dateTimeHelper.ConvertToUtcTime(model.EndDate.Value, _dateTimeHelper.CurrentTimeZone).AddDays(1);

            var newsletterSubscriptions = _newsLetterSubscriptionService.GetAllNewsLetterSubscriptions(
                pageIndex: command.Page - 1,
                pageSize: command.PageSize,
                createdFromUtc: model.StartDate,
                createdToUtc: model.EndDate,
                storeId: _storeContext.CurrentStore.Id

                );


            //command.Page - 1, command.PageSize);

            var gridModel = new DataSourceResult
            {
                Data = newsletterSubscriptions.Select(x =>
                {
                    var m       = x.ToModel();
                    var store   = _storeService.GetStoreById(x.StoreId);
                    m.StoreName = store != null ? store.Name : "Unknown store";
                    m.CreatedOn = _dateTimeHelper.ConvertToUserTime(x.CreatedOnUtc, DateTimeKind.Utc);
                    return(m);
                }),
                Total = newsletterSubscriptions.TotalCount
            };

            return(Json(gridModel));
        }
        public virtual ActionResult 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 = "0"
            });
            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 = "0",
                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")
            });

            //customer roles
            model.AvailableCustomerRoles.Add(new SelectListItem {
                Text = _localizationService.GetResource("Admin.Common.All"), Value = "0"
            });
            foreach (var cr in _customerService.GetAllCustomerRoles(true))
            {
                model.AvailableCustomerRoles.Add(new SelectListItem {
                    Text = cr.Name, Value = cr.Id.ToString()
                });
            }

            return(View(model));
        }
Exemplo n.º 22
0
        public ActionResult SubscriptionDelete(int id, GridCommand command)
        {
            if (_permissionService.Authorize(StandardPermissionProvider.ManageNewsletterSubscribers))
            {
                var subscription = _newsLetterSubscriptionService.GetNewsLetterSubscriptionById(id);

                _newsLetterSubscriptionService.DeleteNewsLetterSubscription(subscription);
            }

            var listModel = new NewsLetterSubscriptionListModel();

            PrepareNewsLetterSubscriptionListModel(listModel);

            return(SubscriptionList(command, listModel));
        }
        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 IActionResult List()
        {
            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 ActionResult SubscriptionUpdate(NewsLetterSubscriptionModel model, GridCommand command)
        {
            if (!ModelState.IsValid)
            {
                var modelStateErrors = this.ModelState.Values.SelectMany(x => x.Errors).Select(x => x.ErrorMessage);
                return(Content(modelStateErrors.FirstOrDefault()));
            }

            var subscription = _newsLetterSubscriptionService.GetNewsLetterSubscriptionById(model.Id);

            subscription.Email  = model.Email;
            subscription.Active = model.Active;

            _newsLetterSubscriptionService.UpdateNewsLetterSubscription(subscription);

            var listModel = new NewsLetterSubscriptionListModel();

            PrepareNewsLetterSubscriptionListModel(listModel);

            return(SubscriptionList(command, listModel));
        }
        public ActionResult SubscriptionDelete(int id, GridCommand command)
        {
            if (!_permissionService.Authorize(StandardPermissionProvider.ManageNewsletterSubscribers))
            {
                return(AccessDeniedView());
            }

            var subscription = _newsLetterSubscriptionService.GetNewsLetterSubscriptionById(id);

            if (subscription == null)
            {
                throw new ArgumentException("No subscription found with the specified id");
            }

            _newsLetterSubscriptionService.DeleteNewsLetterSubscription(subscription);

            var listModel = new NewsLetterSubscriptionListModel();

            PrepareNewsLetterSubscriptionListModel(listModel);

            return(SubscriptionList(command, listModel));
        }
        public ActionResult 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 = "0"
            });
            foreach (var s in _storeService.GetAllStores())
            {
                model.AvailableStores.Add(new SelectListItem {
                    Text = s.Name, Value = s.Id.ToString()
                });
            }

            return(View(model));
        }
Exemplo n.º 28
0
        public ActionResult List()
        {
            if (!_permissionService.Authorize(StandardPermissionProvider.ManageNewsletterSubscribers))
            {
                return(AccessDeniedView());
            }

            var model = new NewsLetterSubscriptionListModel();


            //languages
            model.AvailableLanguageNames.Add(new SelectListItem()
            {
                Text = "---", Value = "0"
            });
            foreach (var lgs in _languageService.GetAllLanguages(true))
            {
                model.AvailableLanguageNames.Add(new SelectListItem()
                {
                    Text = lgs.Name, Value = lgs.Id.ToString()
                });
            }

            var newsletterSubscriptions = _newsLetterSubscriptionService.GetAllNewsLetterSubscriptions(String.Empty, 0, _adminAreaSettings.GridPageSize, true);

            model.NewsLetterSubscriptions = new GridModel <NewsLetterSubscriptionModel>
            {
                Data = newsletterSubscriptions.Select(x =>
                {
                    var m          = x.ToModel();
                    m.LanguageName = _languageService.GetLanguageById(x.LanguageId).Name;
                    m.CreatedOn    = _dateTimeHelper.ConvertToUserTime(x.CreatedOnUtc, DateTimeKind.Utc);
                    return(m);
                }),
                Total = newsletterSubscriptions.TotalCount
            };
            return(View(model));
        }
        public async Task <IActionResult> SubscriptionList(DataSourceRequest command, NewsLetterSubscriptionListModel model, string[] searchCategoryIds)
        {
            bool?isActive = null;

            if (model.ActiveId == 1)
            {
                isActive = true;
            }
            else if (model.ActiveId == 2)
            {
                isActive = false;
            }

            var newsletterSubscriptions = await _newsLetterSubscriptionService.GetAllNewsLetterSubscriptions(model.SearchEmail,
                                                                                                             model.StoreId, isActive, searchCategoryIds, command.Page - 1, command.PageSize);

            var items = new List <NewsLetterSubscriptionModel>();

            foreach (var x in newsletterSubscriptions)
            {
                var m     = x.ToModel();
                var store = await _storeService.GetStoreById(x.StoreId);

                m.StoreName  = store != null ? store.Shortcut : "Unknown store";
                m.CreatedOn  = _dateTimeHelper.ConvertToUserTime(x.CreatedOnUtc, DateTimeKind.Utc).ToString();
                m.Categories = await GetCategoryNames(x.Categories.ToList());

                items.Add(m);
            }
            var gridModel = new DataSourceResult {
                Data  = items,
                Total = newsletterSubscriptions.TotalCount
            };

            return(Json(gridModel));
        }