public async Task<ActionResult> AddToClass(AddWODToClassViewModel model) { Class cls = db.Classes.Find(model.ClassId); try { WOD wod = db.WODs.Single(w => w.Name == model.WODName); cls.WOD = wod; await db.SaveChangesAsync(); return RedirectToAction("Details", new { controller = "Classes", id = model.ClassId }); } catch { model.ClassType = cls.Type; ViewBag.Error = "No WOD was found by that name."; return View(model); } }
// GET: WOD/AddToClass public ActionResult AddToClass(int classId) { string classType = db.Classes.Find(classId).Type; var model = new AddWODToClassViewModel { ClassId = classId, ClassType = classType }; return View(model); }