Пример #1
0
        public async Task <IActionResult> Eat([Bind("ID, Count")] EatVM model)
        {
            if (model.Count == 0)
            {
                model.Count = 1;
            }

            Food food = await _calories.GetFoodAsync(model.ID);

            if (food == null)
            {
                return(RedirectWithMessage("Index", "Can't find requested food"));
            }

            Person who = await _auth.GetCurrentPersonAsync(User);

            await _calories.AddMealAsync(who, food, model.Count);

            return(RedirectWithMessage("Index", "You have eaten {0} {1}{2}", model.Count, food.Name, model.Count == 1 ? "" : "s"));
        }
Пример #2
0
        public async Task <ActionResult> EditAsync(long?id)
        {
            if (id == null)
            {
                return(RedirectWithMessage(nameof(Index), "Missing id"));
            }
            Food current = await _calories.GetFoodAsync(id.Value);

            if (current == null)
            {
                return(RedirectWithMessage(nameof(Index), "Can't find food with id {0}", id.Value));
            }

            return(View(new FoodVM
            {
                Calories = current.Calories,
                Name = current.Name,
                Unit = current.Unit,
            }));
        }