public static bool IsAdmin(string userId)
 {
     return(StudentMsDbSingleton.SingletonStudentDb().Users.FirstOrDefault(user => user.Id == userId).UserType == 3);
 }
        public async Task <ActionResult> Create([Bind(Include = "Id,Name,MobileNumber,Email,DepartmentId,ApplicationUserId")] Teacher teacher)
        {
            if (ModelState.IsValid)
            {
                ApplicationUser applicationUser = new ApplicationUser
                {
                    Email    = teacher.Email,
                    UserName = teacher.Email,
                    UserType = 2
                };

                var userManager = new UserManager <ApplicationUser>(new
                                                                    UserStore <ApplicationUser>(StudentMsDbSingleton.SingletonStudentDb()));
                var studentResult = await userManager.CreateAsync
                                        (applicationUser, teacher.Email);

                if (studentResult.Succeeded)
                {
                    teacher.ApplicationUserId = applicationUser.Id;


                    db.Teachers.Add(teacher);
                    await db.SaveChangesAsync();

                    return(RedirectToAction("Index"));
                }
            }

            ViewBag.ApplicationUserId = new SelectList(db.Users, "Id", "Email", teacher.ApplicationUserId);
            ViewBag.DepartmentId      = new SelectList(db.Departments, "Id", "Name", teacher.DepartmentId);
            return(View(teacher));
        }
Пример #3
0
 public EntityStudentRepository()
 {
     _studentMsDb = StudentMsDbSingleton.SingletonStudentDb();
 }