public ActionResult Create(Workout workout) { if (ModelState.IsValid) { //workout.Id = Guid.NewGuid(); _registry.CreateOrUpdateWorkout(workout); return RedirectToAction("Index"); } return View(workout); }
public void CreateOrUpdateWorkout(Workout workout) { if (workout.Id.Equals(Guid.Empty)) { //create _context.Entry(workout).State = EntityState.Added; _context.SaveChanges(); } else { //update _context.Entry(workout).State = EntityState.Modified; _context.SaveChanges(); } }
public ActionResult Edit(Workout workout) { if (ModelState.IsValid) { _registry.CreateOrUpdateWorkout(workout); return RedirectToAction("Index"); } return View(workout); }