public ActionResult Edit(int id) { var service = CreateGoalItemService(); var detail = service.GetGoalItemByID(id); var model = new GoalItemEdit { GoalItemID = detail.GoalItemID, GoalItemName = detail.GoalItemName, GoalItemPrice = detail.GoalItemPrice, GoalItemLocation = detail.GoalItemLocation }; return(View(model)); }
public bool UpdateGoalItem(GoalItemEdit model) { using (var ctx = new ApplicationDbContext()) { var entity = ctx .GoalItems .Single(e => e.GoalItemID == model.GoalItemID && e.UserID == _userID); entity.GoalItemName = model.GoalItemName; entity.GoalItemPrice = model.GoalItemPrice; entity.GoalItemLocation = model.GoalItemLocation; entity.ModifiedUTC = DateTimeOffset.Now; return(ctx.SaveChanges() == 1); } }
public ActionResult Edit(int id, GoalItemEdit model) { if (!ModelState.IsValid) { return(View(model)); } if (model.GoalItemID != id) { ModelState.AddModelError("", "Id Mismatch"); return(View(model)); } var service = CreateGoalItemService(); if (service.UpdateGoalItem(model)) { TempData["SaveResult"] = "Your item was updated."; return(RedirectToAction("Index")); } ModelState.AddModelError("", "Your item could not be updated."); return(View(model)); }