public ActionResult Create(Teacher teacher) { Console.WriteLine(); int teachCount; teachCount = db.Teachers.Count(); teacher.ID = teachCount + 1; if (ModelState.IsValid) { db.Teachers.Add(teacher); db.SaveChanges(); return RedirectToAction("Index"); } return View(teacher); }
public async Task<ActionResult> Register(RegisterViewModel model) { if (ModelState.IsValid) { var user = new ApplicationUser() { UserName = model.UserName }; var result = await UserManager.CreateAsync(user, model.Password); if (result.Succeeded) { await SignInAsync(user, isPersistent: false); TeacherController teacherController = new TeacherController(); Teacher teacher = new Teacher(); teacher.email = model.UserName; teacher.name = model.UserName; teacher.username = model.UserName; teacher.password = model.Password; teacherController.Create(teacher); return RedirectToAction("Index", "Home"); } else { AddErrors(result); } } // If we got this far, something failed, redisplay form return View(model); }