Пример #1
0
        // My account / Back in stock subscriptions
        public virtual async Task <IActionResult> CustomerSubscriptions(int?pageNumber)
        {
            if (_customerSettings.HideBackInStockSubscriptionsTab)
            {
                return(RedirectToRoute("CustomerInfo"));
            }

            var pageIndex = 0;

            if (pageNumber > 0)
            {
                pageIndex = pageNumber.Value - 1;
            }
            var pageSize = 10;

            var customer = await _workContext.GetCurrentCustomerAsync();

            var store = await _storeContext.GetCurrentStoreAsync();

            var list = await _backInStockSubscriptionService.GetAllSubscriptionsByCustomerIdAsync(customer.Id,
                                                                                                  store.Id, pageIndex, pageSize);

            var model = new CustomerBackInStockSubscriptionsModel();

            foreach (var subscription in list)
            {
                var product = await _productService.GetProductByIdAsync(subscription.ProductId);

                if (product != null)
                {
                    var subscriptionModel = new CustomerBackInStockSubscriptionsModel.BackInStockSubscriptionModel
                    {
                        Id          = subscription.Id,
                        ProductId   = product.Id,
                        ProductName = await _localizationService.GetLocalizedAsync(product, x => x.Name),
                        SeName      = await _urlRecordService.GetSeNameAsync(product),
                    };
                    model.Subscriptions.Add(subscriptionModel);
                }
            }

            model.PagerModel = new PagerModel(_localizationService)
            {
                PageSize         = list.PageSize,
                TotalRecords     = list.TotalCount,
                PageIndex        = list.PageIndex,
                ShowTotalSummary = false,
                RouteActionName  = "CustomerBackInStockSubscriptions",
                UseRouteLinks    = true,
                RouteValues      = new BackInStockSubscriptionsRouteValues {
                    pageNumber = pageIndex
                }
            };

            return(View(model));
        }
        // My account / Back in stock subscriptions
        public ActionResult CustomerSubscriptions(int?page)
        {
            if (_customerSettings.HideBackInStockSubscriptionsTab)
            {
                return(RedirectToRoute("CustomerInfo"));
            }

            int pageIndex = 0;

            if (page > 0)
            {
                pageIndex = page.Value - 1;
            }
            var pageSize = 10;

            var customer = _workContext.CurrentCustomer;
            var list     = _backInStockSubscriptionService.GetAllSubscriptionsByCustomerId(customer.Id,
                                                                                           _storeContext.CurrentStore.Id, pageIndex, pageSize);

            var model = new CustomerBackInStockSubscriptionsModel();

            foreach (var subscription in list)
            {
                var product = subscription.Product;

                if (product != null)
                {
                    var subscriptionModel = new CustomerBackInStockSubscriptionsModel.BackInStockSubscriptionModel
                    {
                        Id          = subscription.Id,
                        ProductId   = product.Id,
                        ProductName = product.GetLocalized(x => x.Name),
                        SeName      = product.GetSeName(),
                    };
                    model.Subscriptions.Add(subscriptionModel);
                }
            }

            model.PagerModel = new PagerModel
            {
                PageSize         = list.PageSize,
                TotalRecords     = list.TotalCount,
                PageIndex        = list.PageIndex,
                ShowTotalSummary = false,
                RouteActionName  = "CustomerBackInStockSubscriptionsPaged",
                UseRouteLinks    = true,
                RouteValues      = new BackInStockSubscriptionsRouteValues {
                    page = pageIndex
                }
            };

            return(View(model));
        }
Пример #3
0
        // My account / Back in stock subscriptions
        public virtual async Task <IActionResult> CustomerSubscriptions(int?pageNumber)
        {
            if (_customerSettings.HideBackInStockSubscriptionsTab)
            {
                return(RedirectToRoute("CustomerInfo"));
            }

            int pageIndex = 0;

            if (pageNumber > 0)
            {
                pageIndex = pageNumber.Value - 1;
            }
            var pageSize = 10;

            var customer = _workContext.CurrentCustomer;
            var list     = await _backInStockSubscriptionService.GetAllSubscriptionsByCustomerId(customer.Id,
                                                                                                 _storeContext.CurrentStore.Id, pageIndex, pageSize);

            var model = new CustomerBackInStockSubscriptionsModel();

            foreach (var subscription in list)
            {
                var product = await _productService.GetProductById(subscription.ProductId);

                if (product != null)
                {
                    var subscriptionModel = new CustomerBackInStockSubscriptionsModel.BackInStockSubscriptionModel {
                        Id                   = subscription.Id,
                        ProductId            = product.Id,
                        ProductName          = product.GetLocalized(x => x.Name, _workContext.WorkingLanguage.Id),
                        AttributeDescription = !subscription.Attributes.Any() ? "" : await _productAttributeFormatter.FormatAttributes(product, subscription.Attributes),
                        SeName               = product.GetSeName(_workContext.WorkingLanguage.Id),
                    };
                    model.Subscriptions.Add(subscriptionModel);
                }
            }

            model.PagerModel = new PagerModel(_localizationService)
            {
                PageSize         = list.PageSize,
                TotalRecords     = list.TotalCount,
                PageIndex        = list.PageIndex,
                ShowTotalSummary = false,
                RouteActionName  = "CustomerBackInStockSubscriptionsPaged",
                UseRouteLinks    = true,
                RouteValues      = new BackInStockSubscriptionsRouteValues {
                    pageNumber = pageIndex
                }
            };

            return(View(model));
        }