Пример #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
 // help function for adding users
 //
 //add Admin
 public void AddAdmin(Admin admin)
 {
     adminDb.dbSet.Add(admin);
     adminDb.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");
 }