public async Task <IActionResult> Edit(int id, [Bind("ID,Name")] DailyNutrition dailyNutrition) { if (id != dailyNutrition.ID) { return(NotFound()); } if (ModelState.IsValid) { try { _context.Update(dailyNutrition); await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!DailyNutritionExists(dailyNutrition.ID)) { return(NotFound()); } else { throw; } } return(RedirectToAction("Index")); } return(View(dailyNutrition)); }
public async Task <IActionResult> Create([Bind("ID,Name")] DailyNutrition dailyNutrition) { if (ModelState.IsValid) { _context.Add(dailyNutrition); await _context.SaveChangesAsync(); return(RedirectToAction("Index")); } return(View(dailyNutrition)); }
public async Task <DailyNutrition> Add(DailyNutrition dailyNutrition) { dailyNutrition.Id = null; dailyNutrition.UserId = GlobalHelpers.CurrentUser.Id; var dbContext = new LMDbContext(); await dbContext.DailyNutritions.AddAsync(dailyNutrition); await dbContext.SaveChangesAsync(); return(dailyNutrition); }