Exemple #1
0
        public static void Initialize(IServiceProvider serviceProvider)
        {
            using (var context = new mvc_testContext(
                       serviceProvider.GetRequiredService <
                           DbContextOptions <mvc_testContext> >()))
            {
                // Look for any movies.
                if (context.user.Any())
                {
                    return;   // DB has been seeded
                }

                context.user.AddRange(
                    new user
                {
                    ID       = "00001",
                    password = "******",      //1212
                    type     = "student"
                },

                    new user
                {
                    ID       = "00002",
                    password = "******",      //1212
                    type     = "teacher"
                }


                    );
                context.SaveChanges();
            }
        }
Exemple #2
0
        public async Task <IActionResult> Create(course course)
        {
            if (ModelState.IsValid)
            {
                if (_context.course.Any(u => u.course_id == course.course_id))
                {
                    ModelState.AddModelError("course_id", "course_id already in use!!!");
                    return(View("Create"));
                }
                if (_context.course.Any(u => u.T_num != course.T_num))
                {
                    ModelState.AddModelError("T_num", "T_num no exist!");
                    return(View("Create"));
                }
                _context.Add(course);
                _context.SaveChanges();

                HttpContext.Session.SetInt32("course_id", course.course_id);

                return(View("Create_sec"));
            }
            return(View("Create"));
        }
Exemple #3
0
        // register user for resgistration
        public IActionResult SignUp(user user)
        {
            System.Console.WriteLine("*************************************************************************");

            if (ModelState.IsValid)
            {
                if (_context.user.Any(u => u.ID == user.ID))
                {
                    ModelState.AddModelError("ID", "ID already in use!!!");
                    return(View("SignUp"));
                }
                if (user.type != "student" && user.type != "teacher")
                {
                    ModelState.AddModelError("type", "no this kind of type(student/teacher)");
                    return(View("SignUp"));
                }
                PasswordHasher <user> Hasher = new PasswordHasher <user>();
                user.password = Hasher.HashPassword(user, user.password);

                _context.Add(user);
                _context.SaveChanges();

                //setting user's first name in session
                HttpContext.Session.SetString("ID", user.ID);
                if (user.type == "student")
                {
                    return(RedirectToAction("SignUp_s"));
                }
                else
                {
                    return(RedirectToAction("SignUp_t"));
                }
                // return RedirectToAction("sucess");
            }
            return(View("sucess"));
        }