Ejemplo n.º 1
0
        // GET: CarModel
        public ActionResult CarModelList(string sortOrder)
        {
            ViewBag.NameSortParm  = String.IsNullOrEmpty(sortOrder) ? "name_desc" : "";
            ViewBag.PriceSortParm = sortOrder == "Price" ? "price_desc" : "Price";
            var mapper    = new MapperConfiguration(cg => cg.CreateMap <CarModelDTO, CarModelView>()).CreateMapper();
            var modelView = mapper.Map <List <CarModelDTO>, List <CarModelView> >(_carModelService.GetCarModels().ToList());

            for (int i = 0; i < modelView.Count; i++)
            {
                modelView[i].Count = GetCountAuto(modelView[i].Id);
            }

            switch (sortOrder)
            {
            case "name_desc":
                modelView = modelView.OrderByDescending(s => s.Name).ToList();
                break;

            case "Price":
                modelView = modelView.OrderBy(s => s.Price).ToList();
                break;

            case "price_desc":
                modelView = modelView.OrderByDescending(s => s.Price).ToList();
                break;

            default:
                modelView = modelView.OrderBy(s => s.Name).ToList();
                break;
            }
            return(View(modelView));
        }
Ejemplo n.º 2
0
        // POST: Car/Create
        public ActionResult CreateCar()
        {
            var ModelsNames = new List <string>();

            foreach (var it in _carModelService.GetCarModels())
            {
                ModelsNames.Add(it.Name);
            }

            return(View(new CreateCarViewModel {
                ValidModels = ModelsNames
            }));
        }
Ejemplo n.º 3
0
 public ActionResult <IEnumerable <CarModel> > getCarModels(int carBrandId)
 {
     try
     {
         var models = carModelService.GetCarModels(carBrandId);
         return(Ok(models));
     }
     catch (NotFoundItemException ex)
     {
         return(NotFound(ex.Message));
     }
     catch (Exception)
     {
         throw;
     }
 }
 public IActionResult GetList()
 {
     return(Ok(new ApiOkResponse(_carModelService.GetCarModels())));
 }