예제 #1
0
 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");
 }
예제 #2
0
        public ActionResult Create(User user)
        {
            if (ModelState.IsValid)
            {
                db.dbSet.Add(user);
                db.SaveChanges();
                return RedirectToAction("Index");
            }

            return View(user);
        }
예제 #3
0
 public ActionResult Edit(User user)
 {
     if (ModelState.IsValid)
     {
         db.Entry(user).State = EntityState.Modified;
         db.SaveChanges();
         return RedirectToAction("Index");
     }
     return View(user);
 }