public ActionResult Edit(int id, FoodDayEdit model) { if (!ModelState.IsValid) { PopulateDateList(); PopulateUserProfiles(model.UserProfileId); return(View(model)); } if (model.FoodDayId != id) { PopulateDateList(); PopulateUserProfiles(model.UserProfileId); ModelState.AddModelError("", "Id Mismatch"); return(View(model)); } var service = CreateFoodDayService(); if (service.UpdateFoodDay(model)) { TempData["SaveResult"] = "Your Food Day was updated."; return(RedirectToAction("Index")); } PopulateDateList(); PopulateUserProfiles(model.UserProfileId); ModelState.AddModelError("", "Your Food Day could not be updated."); return(View(model)); }
public bool UpdateFoodDay(FoodDayEdit model) { var entity = _db .FoodDays .Single(e => e.FoodDayId == model.FoodDayId); entity.UserProfileId = model.UserProfileId; entity.Date = model.Date; entity.ModifiedBy = _db.Users.Find(_userId).FirstName + " " + _db.Users.Find(_userId).LastName; entity.ModifiedUtc = DateTimeOffset.UtcNow; return(_db.SaveChanges() == 1); }
//GET : FoodDay/Edit public ActionResult Edit(int id) { var service = CreateFoodDayService(); var detail = service.GetFoodDayById(id); var model = new FoodDayEdit { FoodDayId = detail.FoodDayId, UserProfileId = detail.UserProfileId, Date = detail.Date }; PopulateDateList(); PopulateUserProfiles(detail.UserProfileId); return(View(model)); }