Exemple #1
0
        public ActionResult Index(ChooseColourFor? chooseColourFor, PagerParameters pagerParameters)
        {
            var viewModel = new ColourIndexViewModel(chooseColourFor);

            if (chooseColourFor == null)
            {
                return View(viewModel);
            }

            if (chooseColourFor.Value == ChooseColourFor.Product)
            {
                var pager = new Pager(_siteService.GetSiteSettings(), pagerParameters.Page, pagerParameters.PageSize);

                var productColours = _productColourRepository.Table
                    .Where(p => p.ProdColorCulture == cultureUsed)
                    .OrderBy(p => p.Name)
                    .Skip(pager.GetStartIndex())
                    .Take(pager.PageSize);

                var pagerShape = Shape.Pager(pager).TotalItemCount(_productColourRepository.Table.Where(p => p.ProdColorCulture == cultureUsed).Count());

                viewModel.Colors = productColours;
                viewModel.Pager = pagerShape;
            }
            else if (chooseColourFor == ChooseColourFor.Swatch)
            {
                var pager = new Pager(_siteService.GetSiteSettings(), pagerParameters.Page, pagerParameters.PageSize);

                var swatchColours = _swatchColourRepository.Table
                    .Where(p => p.SwatchCulture == cultureUsed)
                    .OrderBy(p => p.Name)
                    .Skip(pager.GetStartIndex())
                    .Take(pager.PageSize)
                    .Select(s => new SwatchColourViewModel
                    {
                        Id = s.Id,
                        Name = s.Name,
                        Value = ColorTranslator.ToHtml(Color.FromArgb(s.Red, s.Green, s.Blue)),
                        InStock = s.InStock
                    });

                var pagerShape = Shape.Pager(pager).TotalItemCount(_swatchColourRepository.Table.Where(s => s.SwatchCulture == cultureUsed).Count());

                viewModel.Colors = swatchColours;
                viewModel.Pager = pagerShape;
            }

            return View(viewModel);
        }
 public ColourIndexViewModel(ChooseColourFor? chooseColourFor)
 {
     ChooseColourFor = chooseColourFor;
 }