public ActionResult Edit(int id) { var service = CreateWeekService(); var detail = service.GetWeekById(id); var model = new WeekEdit { WeekId = detail.WeekId, SeasonNumber = detail.SeasonNumber, SeasonWeek = detail.SeasonWeek, StadiumName = detail.StadiumName, PlayerId = detail.PlayerId, }; return(View(model)); }
public bool UpdateWeek(WeekEdit model) { using (var ctx = new ApplicationDbContext()) { var entity = ctx .Weeks .Single(e => e.WeekId == model.WeekId && e.OwnerId == _userId); entity.SeasonNumber = model.SeasonNumber; entity.SeasonWeek = model.SeasonWeek; entity.StadiumName = model.StadiumName; entity.PlayerId = model.PlayerId; return(ctx.SaveChanges() == 1); } }
public ActionResult Edit(int id, WeekEdit model) { if (!ModelState.IsValid) { return(View(model)); } if (model.WeekId != id) { ModelState.AddModelError("", "Id Mismatch"); return(View(model)); } var service = CreateWeekService(); if (service.UpdateWeek(model)) { TempData["SaveResult"] = "Your week was updated."; return(RedirectToAction("Index")); } ModelState.AddModelError("", "Your week could not be updated."); return(View(model)); }