public ActionResult Edit(int id) { var service = CreateGamerService(); var detail = service.GetGamerById(id); var model = new GamerEdit { GamerId = detail.GamerId, GamerTag = detail.GamerTag, FirstName = detail.FirstName, LastName = detail.LastName, EmailAddress = detail.EmailAddress, Location = detail.Location, Bio = detail.Bio }; return(View(model)); }
public bool UpdateGamer(GamerEdit model) { using (var ctx = new ApplicationDbContext()) { var entity = ctx .Gamers .Single(e => e.GamerId == model.GamerId && e.PlayerId == _gamerId); entity.GamerTag = model.GamerTag; entity.FirstName = model.FirstName; entity.LastName = model.LastName; entity.EmailAddress = model.EmailAddress; entity.Location = model.Location; entity.Bio = model.Bio; return(ctx.SaveChanges() == 1); } }
public ActionResult Edit(int id, GamerEdit model) { if (!ModelState.IsValid) { return(View(model)); } if (model.GamerId != id) { ModelState.AddModelError("", "Id Mismatch"); return(View(model)); } var service = CreateGamerService(); if (service.UpdateGamer(model)) { TempData["SaveResult"] = "Your gamer profile was updated."; return(RedirectToAction("Index")); } ModelState.AddModelError("", "Your profile could not be updated."); return(View(model)); }