public async Task <IActionResult> Register(Form_User_ViewModel _model)
        {
            if (ModelState.IsValid)
            {
                _model.AppRoles = this._identityContext.Roles
                                  .Where(r => r.Name != "Admin").ToList();

                string _userName = _model.AppUser.FirstName.Substring(0, 1) +
                                   _model.AppUser.LastName.Replace(" ", string.Empty).ToLower();

                string _verificationCode = Guid.NewGuid().ToString()
                                           .Replace("-", string.Empty).ToLower();

                AppUser _appUser = new AppUser
                {
                    UserName         = _userName,
                    FirstName        = _model.AppUser.FirstName,
                    LastName         = _model.AppUser.LastName,
                    Address          = _model.AppUser.Address,
                    ContactNumber    = _model.AppUser.ContactNumber,
                    Email            = _model.AppUser.EmailAddress,
                    EmailAddress     = _model.AppUser.EmailAddress,
                    IsVerified       = true,
                    VerificationCode = _verificationCode
                };

                var _getRole = _model.AppRoles
                               .SingleOrDefault(m => m.Id == _model.AppUser.UserType);
                _appUser.UserType = _getRole.Id;

                string _newPasswordHash = this._userManager.PasswordHasher
                                          .HashPassword(_appUser, _model.AppUser.Password);
                _appUser.PasswordHash = _newPasswordHash;

                IdentityResult _result = await this._userManager
                                         .CreateAsync(_appUser, _model.AppUser.Password);

                if (_result.Succeeded)
                {
                    // Assign role to registered user
                    if (!await this._userManager.IsInRoleAsync(_appUser, _getRole.Name))
                    {
                        await this._userManager.AddToRoleAsync(_appUser, _getRole.Name);
                    }
                }
                else
                {
                    foreach (IdentityError _error in _result.Errors)
                    {
                        ModelState.AddModelError(_error.Code, _error.Description);
                    }
                }
            }

            return(RedirectToAction("Index", "Home"));
        }
        public ViewResult Register()
        {
            ViewBag.Title = "Registration";

            Form_User_ViewModel _model = new Form_User_ViewModel
            {
                AppUser  = new AppUser(),
                AppRoles = this._identityContext.Roles
                           .Where(r => r.Name != "Admin").ToList()
            };

            return(View(_model));
        }
        public ViewResult UserList()
        {
            ViewBag.Title = "List of Users";

            this._users          = new Form_User_ViewModel();
            this._users.AppUsers = this._context.AppUsers
                                   .Where(u => u.UserType != null)
                                   .OrderBy(u => u.Id);
            this._users.AppRoles = this._context.Roles
                                   .Where(r => r.Name != "Admin").ToList();

            return(View(this._users));
        }