public async Task <IActionResult> Edit(int id, [Bind("MealEntryId,MealTime,Calories,PetId")] MealEntry mealEntryToUpdate, int page = 1) { if (User.Identity.IsAuthenticated) { if (id != mealEntryToUpdate.MealEntryId) { return(NotFound()); } if (ModelState.IsValid) { var updateStatus = await _mealEntryService.UpdateMealEntryAsync(mealEntryToUpdate); if (!updateStatus) { return(RedirectToAction("Index", "EditEntries", new { error = true, msgToDisplay = "An error has occured with the databse." })); } var goalReached = _mealEntryService.DailyMealGoalReached(mealEntryToUpdate.PetId); return(RedirectToAction("Index", "EditEntries", new { id = page, updated = true, msgToDisplay = "Meal entry has been successfully updated." })); } ViewBag.Page = page; return(View(mealEntryToUpdate)); } return(RedirectToAction("Index", "NotAuthorized")); }
public async Task <bool> UpdateMealEntry(int entryId, int calories, int petId) { var mealEntry = _mealEntryService.GetAllMealEntries().Where(e => e.MealEntryId == entryId).FirstOrDefault(); mealEntry.PetId = petId; mealEntry.Calories = calories; return(await _mealEntryService.UpdateMealEntryAsync(mealEntry)); }