Esempio n. 1
0
        public SearchTyreViewModel LoadDataToViewBag(IEnumerable <Tyre> tyres)
        {
            if (tyres == null)
            {
                new HttpStatusCodeResult(HttpStatusCode.BadRequest, "Invalid search");
            }
            IEnumerable <int>    sizeDistinct    = tyres.Where(t => t.Stock > 0).Select(t => t.Size).Distinct();
            IEnumerable <int>    widthDistinct   = tyres.Where(t => t.Stock > 0).Select(t => t.Width).Distinct();
            IEnumerable <int>    heightDistinct  = tyres.Where(t => t.Stock > 0).Select(t => t.Height).Distinct();
            IEnumerable <string> seasonsDistinct = tyres.Where(t => t.Stock > 0).Select(t => t.Season.ToString()).Distinct();
            IEnumerable <string> tyreBrands      = tyres.Select(t => t.Brand).Distinct();

            var sizes   = new SelectList(sizeDistinct);
            var width   = new SelectList(widthDistinct);
            var heights = new SelectList(heightDistinct);
            var seasons = new SelectList(seasonsDistinct);
            var brands  = new SelectList(tyreBrands);

            var vm = new SearchTyreViewModel()
            {
                Sizes   = sizes,
                Widths  = width,
                Height  = heights,
                Seasons = seasons,
                Brands  = brands
            };

            return(vm);
        }
Esempio n. 2
0
        public PartialViewResult Search()
        {
            var tyres = this.service.GetAllTyres();
            SearchTyreViewModel vm = null;

            if (tyres != null)
            {
                vm = this.service.LoadDataToViewBag(tyres);
            }
            return(PartialView("_TyresDropDown", vm));
        }