Пример #1
0
        public ActionResult AddUser(FormCollection fc)
        {
            var newuser = new ApplicationUser {
                UserName = fc["email"], Email = fc["email"]
            };
            var result = userManager.Create(newuser, fc["password"]);

            if (result.Succeeded)
            {
                var roleManager = new RoleManager <IdentityRole>(new RoleStore <IdentityRole>(new ApplicationDbContext()));
                userManager.AddToRole(newuser.Id, fc["ddl"]);
                if (fc["ddl"] == "Student")
                {
                    using (MoodleDb db = new MoodleDb())
                    {
                        Student s = new Student
                        {
                            Id       = newuser.Id,
                            UserName = newuser.UserName
                        };
                        db.Students.Add(s);
                        Directory.CreateDirectory(Path.Combine(Server.MapPath("~/UploadedFiles"), newuser.Id));
                        db.SaveChanges();
                    }
                }
            }
            else
            {
                TempData["msg"] = "An error occured while adding user";
            }
            return(RedirectToAction("Index", "Admin"));
        }
Пример #2
0
        public string DeleteUser(string id)
        {
            userManager.Delete(userManager.FindById(id));
            MoodleDb db = new MoodleDb();

            db.Students.Remove(db.Students.Find(id));

            db.SaveChanges();
            return("User deleted");
        }
Пример #3
0
        public async Task <ActionResult> Register(RegisterViewModel model)
        {
            if (ModelState.IsValid)
            {
                var user = new ApplicationUser {
                    UserName = model.Email, Email = model.Email
                };
                var result = await UserManager.CreateAsync(user, model.Password);

                if (result.Succeeded)
                {
                    Directory.CreateDirectory(Path.Combine(Server.MapPath("~/UploadedFiles"), user.Id));
                    var roleManager = new RoleManager <IdentityRole>(new RoleStore <IdentityRole>(new ApplicationDbContext()));
                    UserManager.AddToRole(user.Id, "Student");
                    using (MoodleDb db = new MoodleDb())
                    {
                        Student s = new Student
                        {
                            Id       = user.Id,
                            UserName = user.UserName
                        };
                        db.Students.Add(s);
                        db.SaveChanges();
                    }
                    await SignInManager.SignInAsync(user, isPersistent : false, rememberBrowser : false);

                    // For more information on how to enable account confirmation and password reset please visit https://go.microsoft.com/fwlink/?LinkID=320771
                    // Send an email with this link
                    // string code = await UserManager.GenerateEmailConfirmationTokenAsync(user.Id);
                    // var callbackUrl = Url.Action("ConfirmEmail", "Account", new { userId = user.Id, code = code }, protocol: Request.Url.Scheme);
                    // await UserManager.SendEmailAsync(user.Id, "Confirm your account", "Please confirm your account by clicking <a href=\"" + callbackUrl + "\">here</a>");

                    return(RedirectToAction("Enroll", "Student"));
                }
                AddErrors(result);
            }

            // If we got this far, something failed, redisplay form
            return(View(model));
        }
Пример #4
0
 public QuizController()
 {
     obQuizDbEntities = new MoodleDb();
 }
Пример #5
0
 public AdminResultController()
 {
     obQuizDbEntities = new MoodleDb();
 }
Пример #6
0
 public AdminQuizController()
 {
     objquizdbEntities = new MoodleDb();
 }