Example #1
0
        public IActionResult Cars(int id)
        {
            var generation = generationsService.GetById(id);

            if (generation == null)
            {
                return(this.BadRequest());
            }

            var imageUrls = imagesService.GetImageUrls(GlobalConstants.GENERATION_PHOTO_PATH_TEMPLATE, id.ToString());

            var cars = carsService.GetAllForGeneration(id)
                       .To <DisplayCarWithEngineModel>()
                       .ToList();

            var viewModel = new DisplayCarsWithImagesModel
            {
                Cars      = cars,
                ImageUrls = imageUrls
            };

            viewModel.GenerationId = generation.Id;

            this.ViewBag.Make       = generation.Model.Make.Name;
            this.ViewBag.Model      = generation.Model.Name;
            this.ViewBag.Generation = generation.Name;

            return(this.View(viewModel));
        }
        public JsonResult FetchCars(int id)
        {
            var cars = carsService.GetAllForGeneration(id)
                       .To <CarDTO>()
                       .OrderBy(x => x.EngineMaxHP)
                       .ThenBy(x => x.DisplayText);

            return(Json(cars));
        }