public ActionResult Edit(int id) { var service = CreateBandService(); var detail = service.GetBandById(id); var model = new BandEdit { BandId = detail.BandId, Name = detail.Name, Members = detail.Members, YearsActive = detail.YearsActive, NumberOfAlbums = detail.NumberOfAlbums }; return(View(model)); }
public bool UpdateBand(BandEdit model) { using (var ctx = new ApplicationDbContext()) { var entity = ctx .Bands .Single(e => e.BandId == model.BandId && e.UserId == _userId); entity.Name = model.Name; entity.Members = model.Members; entity.YearsActive = model.YearsActive; entity.NumberOfAlbums = model.NumberOfAlbums; return(ctx.SaveChanges() == 1); } }
public ActionResult Edit(int id, BandEdit model) { if (!ModelState.IsValid) { return(View(model)); } if (model.BandId != id) { ModelState.AddModelError("", "Id Does Not Match!"); return(View(model)); } var service = CreateBandService(); if (service.UpdateBand(model)) { TempData["SaveResult"] = "Band Updated!"; return(RedirectToAction("Index")); } ModelState.AddModelError("", "Could Not Update Band!"); return(View(model)); }