Beispiel #1
0
        private FoodItemTableViewModel GetFoodItemTableViewModel(DateTime date)
        {
            List <FoodItem>          foodItems         = _foodItemServices.GetFoodItems(date, UserId).OrderByDescending(x => x.Id).ToList();
            List <FoodItemViewModel> foodItemViewModel = Mapper.Map <List <FoodItem>, List <FoodItemViewModel> >(foodItems);

            var viewModel = new FoodItemTableViewModel()
            {
                FoodItems = foodItemViewModel
            };

            return(viewModel);
        }
        public ActionResult Refresh(DateTime date)
        {
            User user = _userServices.GetUser(User.Identity.Name);

            // Order by Id, so the most recent item is at the top of the list.
            List <FoodItem>  foodItems  = _foodItemServices.GetFoodItems(date, user.Id).OrderByDescending(x => x.Id).ToList();
            List <Favourite> favourites = _foodItemServices.GetFavourites(user.Id).OrderByDescending(x => x.Name).ToList();

            var viewModel = new FoodItemListViewModel()
            {
                FoodItems  = Mapper.Map <IEnumerable <FoodItem>, IEnumerable <FoodItemViewModel> >(foodItems),
                Favourites = Mapper.Map <IEnumerable <Favourite>, IEnumerable <FavouriteViewModel> >(favourites)
            };

            return(Json(viewModel, JsonRequestBehavior.AllowGet));
        }