Esempio n. 1
0
        public IHttpActionResult GetDish(int id)
        {
            try
            {
                dishesService = new DishesService(User.Identity.Name);
            }
            catch (UserNotFoundException)
            {
                return(NotFound());
            }

            Dish dish = dishesService.Get(id);

            var config = new MapperConfiguration(cfg =>
            {
                cfg.CreateMap <Dish, DishDTO>();
            });
            IMapper iMapper = config.CreateMapper();

            DishDTO dishDTO = iMapper.Map <Dish, DishDTO>(dish);

            return(Ok(dishDTO));
        }
Esempio n. 2
0
        // GET: api/Dishes
        public IEnumerable <DishDTO> GetDishes(
            string filterOption = null, string sortOption = null,
            int pageSize        = 20, int pageNumber      = 1)
        {
            try
            {
                dishesService = new DishesService(User.Identity.Name);
            }
            catch (UserNotFoundException)
            {
                return(null);
            }

            IEnumerable <Dish> dishes = dishesService.Get(
                filterOption, sortOption, pageSize, pageNumber);

            var config = new MapperConfiguration(cfg =>
            {
                cfg.CreateMap <Dish, DishDTO>();
            });
            IMapper iMapper = config.CreateMapper();

            return(iMapper.Map <IEnumerable <Dish>, IEnumerable <DishDTO> >(dishes));
        }