예제 #1
0
 //Add user with his role
 public void AddUserWithRole(string role,int id, Admin admin,Teacher teacher,Student student)
 {
     admin.userId = teacher.UserId = student.userId = id;
     switch(role)
     {
         case "SchoolAdmin": AddAdmin(admin);
             break;
         case "Teacher": AddTeacher(teacher);
             break;
         case "Student": AddStudent(student);
             break;
     }
 }
예제 #2
0
 //add user
 public void AddStudent(Student student)
 {
     studentDb.dbSet.Add(student);
     studentDb.SaveChanges();
 }
예제 #3
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");
 }