public ActionResult Edit(int id) { var service = CreateStatService(); var detail = service.GetStatById(id); var model = new StatEdit { StatId = detail.StatId, Weight = detail.Weight, WeightDate = detail.WeightDate, GoalMessage = detail.GoalMessage }; return(View(model)); }
public bool UpdateStat(StatEdit model) { using (var ctx = new ApplicationDbContext()) { var entity = ctx .Stats .Single(e => e.StatId == model.StatId); entity.Weight = (int)model.Weight; entity.WeightDate = DateTimeOffset.Now; entity.GoalMessage = model.GoalMessage; return(ctx.SaveChanges() == 1); } }
public ActionResult Edit(int id, StatEdit model) { if (!ModelState.IsValid) { return(View(model)); } if (model.StatId != id) { ModelState.AddModelError("", "Id Doesn't Match"); return(View(model)); } var service = CreateStatService(); if (service.UpdateStat(model)) { TempData["SaveResult"] = "Stat info was updated."; return(RedirectToAction("Index")); } ModelState.AddModelError("", "Stat info could not be updated."); return(View(model)); }