Esempio n. 1
0
        public ActionResult Index(int?categoryId, string viewName, string keywords = null, bool?featured = null,
                                  int?count = null, int?pageSize = null, int[] optionIds = null)
        {
            ProductGridViewModel model = loadProductGridViewModel(categoryId, 1,
                                                                  pageSize ?? settings.Get <int>(SettingField.ProductsPerPage), keywords, featured, count,
                                                                  optionIds);

            return(PartialView(viewName, model));
        }
Esempio n. 2
0
        public ActionResult Related(int productId, string viewName, int?count = null)
        {
            var categoryId = productFinder.Find(productId).Categories.First().Id;

            ProductGridViewModel model = loadProductGridViewModel(categoryId, 1,
                                                                  count ?? settings.Get <int>(SettingField.ProductsPerPage), maxCount: count,
                                                                  excludeProductId: productId);

            return(PartialView(viewName, model));
        }
Esempio n. 3
0
        public ActionResult Destroy([DataSourceRequest] DataSourceRequest request, ProductGridViewModel model)
        {
            if (model != null)
            {
                this.Data.Products.DeleteById(model.Id);
                this.Data.SaveChanges();
            }

            return(this.GridOperation(model, request));
        }
        public ActionResult Index(int page = 1)
        {
            var pagesCount = this.products.All().Count();
            var viewModel = new ProductGridViewModel
            {
                CurrentPage = page,
                PagesCount = (int)Math.Ceiling(pagesCount / (decimal)PageSize),
                Products = this.products.All().To<ProductViewModel>().OrderBy(p => p.Price).Skip((page - 1) * PageSize).Take(PageSize).ToList()
            };

            return View(viewModel);
        }
Esempio n. 5
0
        public JsonResult List(int?categoryId, int page = 1, int pageSize       = 0, string keywords = null,
                               bool?featured            = null, int[] optionIds = null)
        {
            if (pageSize == 0)
            {
                pageSize = settings.Get <int>(SettingField.ProductsPerPage);
            }

            ProductGridViewModel model = loadProductGridViewModel(categoryId, page, pageSize, keywords: keywords,
                                                                  featured: featured, optionIds: optionIds);

            return(JsonSuccess(model));
        }
Esempio n. 6
0
        private ProductGridViewModel loadProductGridViewModel(int?categoryId, int page, int pageSize, string keywords = null, bool?featured = null,
                                                              int?maxCount = null, int[] optionIds = null, int?excludeProductId = null)
        {
            IQueryable <Product> products = productFinder.Find(categoryId, keywords: keywords, featured: featured,
                                                               optionIds: optionIds);

            if (excludeProductId.HasValue)
            {
                products = products.Where(p => p.Id != excludeProductId);
            }
            if (maxCount.HasValue)
            {
                products = products.Take(maxCount.Value);
            }
            var count = products.Count();

            if (count == 0)
            {
                products = productFinder.Find(categoryId, keywords: keywords, includeChildCategories: true,
                                              featured: featured, optionIds: optionIds);
                if (excludeProductId.HasValue)
                {
                    products = products.Where(p => p.Id != excludeProductId);
                }
                if (maxCount.HasValue)
                {
                    products = products.Take(maxCount.Value);
                }
                count = products.Count();
            }

            var model = new ProductGridViewModel();

            model.Page          = page;
            model.TotalProducts = count;
            model.TotalPages    = ((model.TotalProducts - 1) / pageSize) + 1;
            model.Products      = Mapper.Map <ProductViewModel[]>(products.GetPage(page, pageSize));
            foreach (var productViewModel in model.Products)
            {
                productViewModel.Url = Url.Action("Details",
                                                  new { id = productViewModel.Id, slug = productViewModel.Name.ToSlug() });
                productViewModel.PrimaryPhotoId = uploadService.FindPrimaryIdByProduct(productViewModel.Id);
            }
            model.CategoryId = categoryId;
            model.Keywords   = keywords;
            model.Featured   = featured;
            return(model);
        }
        protected override void OnInitialized()
        {
            try
            {
                //creating the view model will get the product data and grid parameters
                _gridViewModel = new ProductGridViewModel();

                _dialogViewModel = new DialogViewModel()
                {
                    ConfirmButtonName = "Ok", ShowCancelButton = false
                };

                _editorViewModel = new ProductEditorViewModel();
            }
            catch (System.Exception ex)
            {
                _dialogViewModel.Show("Error", ex.Message, ex);
            }
            base.OnInitialized();
        }