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)); }
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); }
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 })); }