public bool UpdateBoss(BossEdit model) { using (var ctx = new ApplicationDbContext()) { var entity = ctx.Bosses.Single(e => e.BossID == model.BossID && e.VideoGameID == model.VideoGameID); entity.BossName = model.BossName; entity.BossNotes = model.BossNotes; entity.BossBeaten = model.BossBeaten; return(ctx.SaveChanges() == 1); } }
public bool UpdateBoss(BossEdit model) { var entity = ctx.Bosses.Single(e => e.ID == model.ID); entity.Name = model.Name; entity.Health = model.Health; entity.Description = model.Description; entity.Weakness = model.Weakness; entity.Tips = model.Tips; entity.Location = model.Location; entity.LocationID = model.LocationID; return(ctx.SaveChanges() == 1); }
public ActionResult BossEdit(int id) { var service = CreateBossService(); var detail = service.BossDetails(id); var model = new BossEdit { BossID = detail.BossID, BossName = detail.BossName, BossNotes = detail.BossNotes, BossBeaten = detail.BossBeaten, VideoGameID = detail.VideoGameID }; return(View(model)); }
//GET: Boss/Edit public ActionResult Edit(int id) { var service = new BossService(); var detail = service.GetBossByID(id); var locationService = new LocationService(); ViewBag.LocationID = new SelectList(ctx.Locations.ToList(), "ID", "Name"); var model = new BossEdit { Name = detail.Name, Description = detail.Description, Health = detail.Health, Weakness = detail.Weakness, Location = detail.Location, LocationID = detail.LocationID, Tips = detail.Tips }; return(View(model)); }
public ActionResult Edit(int id, BossEdit model) { if (!ModelState.IsValid) { return(View(model)); } if (model.ID != id) { ModelState.AddModelError("", "Wrong ID"); return(View(model)); } var service = new BossService(); if (service.UpdateBoss(model)) { TempData["SaveResult"] = "Boss updated"; return(RedirectToAction("Index")); } ModelState.AddModelError("", "Error"); return(View(model)); }
public ActionResult BossEdit(int id, BossEdit model) { if (!ModelState.IsValid) { return(View(model)); } if (model.BossID != id) { ModelState.AddModelError("", "Id Mismatch"); return(View(model)); } var service = CreateBossService(); if (service.UpdateBoss(model)) { TempData["SaveResult"] = "Your Boss was updated."; return(RedirectToAction("Index", "VideoGames")); } ModelState.AddModelError("", "Your Boss could not be updated."); return(View(model)); }