public ActionResult Edit(int id, GiftEdit model) { var db = new PersonService(); ViewBag.PersonID = new SelectList(db.GetPerson().OrderBy(e => e.FullName), "PersonID", "FullName"); if (!ModelState.IsValid) { return(View(model)); } if (model.GiftID != id) { ModelState.AddModelError("", "Id mismatch"); return(View(model)); } var service = CreateGiftService(); if (service.UpdateGift(model)) { TempData["SaveResult"] = "Gift was updated"; return(RedirectToAction("Index")); } ModelState.AddModelError("", "Gift could not be saved"); return(View(model)); }
// GET for Edit public ActionResult Edit(int id) { var service = CreateGiftService(); var detail = service.GetGiftById(id); var model = new GiftEdit { GiftId = detail.GiftId, GiftName = detail.GiftName, GiftDescription = detail.GiftDescription, RegistryEventId = detail.RegistryEventId, RegistryEvent = detail.RegistryEvent }; return(View(model)); }
public bool UpdateGift(GiftEdit model) { using (var ctx = new ApplicationDbContext()) { var entity = ctx .Gifts .Single(e => e.GiftID == model.GiftID); /*&& e.OwnerID == _userID);*/ entity.Description = model.Description; entity.BoughtGift = model.BoughtGift; entity.Person = model.Person; return(ctx.SaveChanges() == 1); } }
public bool UpdateGift(GiftEdit model) { using (var ctx = new ApplicationDbContext()) { var entity = ctx .Gifts .Single(e => e.GiftId == model.GiftId); entity.GiftId = model.GiftId; entity.GiftName = model.GiftName; entity.GiftDescription = model.GiftDescription; entity.RegistryEventId = model.RegistryEventId; entity.RegistryEvent = model.RegistryEvent; return(ctx.SaveChanges() == 1); } }
public ActionResult Edit(int id) { var service = CreateGiftService(); var detail = service.GetGiftByID(id); var db = new PersonService(); ViewBag.PersonID = new SelectList(db.GetPerson().OrderBy(e => e.FullName), "PersonID", "FullName"); var model = new GiftEdit { GiftID = detail.GiftID, Description = detail.Description, BoughtGift = detail.BoughtGift, Person = detail.Person }; return(View(model)); }
public ActionResult Edit(int id, GiftEdit model) { if (!ModelState.IsValid) { return(View(model)); } if (model.GiftId != id) { ModelState.AddModelError("", "ID Mismatch"); return(View(model)); } var service = CreateGiftService(); if (service.UpdateGift(model)) { TempData["SaveResult"] = "Your Event was updated"; return(RedirectToAction("Index", new { id = model.RegistryEventId })); } ModelState.AddModelError("", "Your Event could not be updated."); return(View(model)); }