public ActionResult Register(User user,string role, Admin admin,Teacher teacher,Student student) { // Attempt to register the user MembershipCreateStatus createStatus; Membership.CreateUser(user.userName, user.password, user.email, null, null, true, null, out createStatus); if (createStatus == MembershipCreateStatus.Success) { //add to user database db.dbSet.Add(user); db.SaveChanges(); //add role Roles.AddUserToRole(user.userName, role); //add to our tables int id = GetUserIdByUsername(user.userName); AddUserWithRole(role,id,admin, teacher, student); FormsAuthentication.SetAuthCookie(user.userName, false /* createPersistentCookie */); return RedirectToAction("Index"); } else { ModelState.AddModelError("", ErrorCodeToString(createStatus)); } return RedirectToAction("Index"); }
public ActionResult Create(User user) { if (ModelState.IsValid) { db.dbSet.Add(user); db.SaveChanges(); return RedirectToAction("Index"); } return View(user); }
public ActionResult Edit(User user) { if (ModelState.IsValid) { db.Entry(user).State = EntityState.Modified; db.SaveChanges(); return RedirectToAction("Index"); } return View(user); }