public IActionResult AddUserToRole(string Email, string RoleName)
        {
            Lab8Model      user   = _UserManager.FindByEmailAsync(Email).Result;
            IdentityResult result = _UserManager.AddToRoleAsync(user, RoleName).Result;

            //Check the status of the result
            if (!result.Succeeded)
            {
                throw new Exception(result.Errors.Select(e => e.Description).Aggregate((a, b) => a + "," + b));
            }
            return(RedirectToAction("Index"));
        }
        public IActionResult CreateGroup(GroupModel model)
        {
            if (!ModelState.IsValid)
            {
                return(View(model));
            }
            Lab8Model      user   = _UserManager.FindByNameAsync(_UserManager.GetUserName(User)).Result;
            IdentityResult result = _UserManager.AddToRoleAsync(user, "Admin").Result;

            if (!result.Succeeded)
            {
                throw new Exception(result.Errors.Select(e => e.Description).Aggregate((a, b) => a + "," + b));
            }
            return(Create(model));
        }
        public async Task <IActionResult> OnPostAsync(string returnUrl = null)
        {
            returnUrl = returnUrl ?? Url.Content("~/");
            if (ModelState.IsValid)
            {
                var user = new Lab8Model {
                    UserName = Input.Email, Email = Input.Email,
                    FunFact  = Input.FunFact, Age = Input.Age
                };
                var result = await _userManager.CreateAsync(user, Input.Password);

                if (result.Succeeded)
                {
                    _logger.LogInformation("User created a new account with password.");

                    var code = await _userManager.GenerateEmailConfirmationTokenAsync(user);

                    var callbackUrl = Url.Page(
                        "/Account/ConfirmEmail",
                        pageHandler: null,
                        values: new { userId = user.Id, code = code },
                        protocol: Request.Scheme);

                    await _emailSender.SendEmailAsync(Input.Email, "Confirm your email",
                                                      $"Please confirm your account by <a href='{HtmlEncoder.Default.Encode(callbackUrl)}'>clicking here</a>.");

                    await _signInManager.SignInAsync(user, isPersistent : false);

                    return(LocalRedirect(returnUrl));
                }
                foreach (var error in result.Errors)
                {
                    ModelState.AddModelError(string.Empty, error.Description);
                }
            }

            // If we got this far, something failed, redisplay form
            return(Page());
        }
 public IActionResult Index(Lab8Model tom)
 {
     return(View(tom));
 }
 public HomeController()
 {
     mod = new Lab8Model();
 }