示例#1
0
        public async Task <IActionResult> AddMeal(int id)
        {
            AddMealToDayModel model = await this.daysService.GetDayMealsByIdAsync(id, this.User.Identity.Name);

            this.ViewData["id"] = id;

            return(this.View(model));
        }
示例#2
0
        public async Task <AddMealToDayModel> GetDayMealsByIdAsync(int id, string username)
        {
            var meals = await this.mealsService.GetAllUserMealsAsync(username);

            var model = new AddMealToDayModel()
            {
                Id    = id,
                Meals = meals.Select(m => new SelectListItem(m.Name, m.Id.ToString()))
            };

            return(model);
        }
示例#3
0
        public async Task <IActionResult> AddMeal(int dayId, AddMealToDayModel model)
        {
            try
            {
                await this.daysService.AddMealToDayAsync(dayId, model.Id, this.User.Identity.Name);
            }
            catch (Exception)
            {
                this.ModelState.AddModelError(string.Empty, alreadyAddedMeal);

                return(await this.AddMeal(dayId));
            }

            return(this.RedirectToAction(ActionConstants.Details, ControllerConstants.Days, new { id = dayId }));
        }