public ActionResult <FoodTruckModel> Get([FromQuery] string tag = null)
        {
            // Since we have just one filter possibility, we'll leave this as a simple conditional statement
            // If we had more/more complex filter criteria, then splitting the logic into multiple methods would be in order
            var result = (tag == null)
                ? _foodTruckService.GetAllFoodTrucks()
                : _foodTruckService.GetFoodTrucksByTag(tag);

            return(CreateResponse <List <FoodTruck>, List <FoodTruckModel> >(result));
        }
예제 #2
0
        public IActionResult Get([FromQuery] string tag = null)
        {
            // Since we have just one filter possibility, we'll leave this as a simple if statement
            // If we had more/more complex filter criteria, then splitting the logic into multiple methods would be in order
            List <FoodTruck> foodTrucks = null;

            if (tag == null)
            {
                foodTrucks = _foodTruckService.GetAllFoodTrucks();
            }
            else
            {
                foodTrucks = _foodTruckService.GetFoodTrucksByTag(tag);
            }
            var models = _mapper.Map <List <FoodTruck>, List <FoodTruckModel> >(foodTrucks);

            return(Ok(models));
        }