// public IActionResult ChangePassword()
        // {
        //     return View();
        // }

        public async Task <ActionResult> ChangePassword(string oldpassword, string password, string repassword)
        {
            string hashpass;
            var    userId = HttpContext.Session.GetInt32("userId");

            if (userId == null)
            {
                return(BadRequest());
            }
            else
            {
                var user = await _context.Users.FirstOrDefaultAsync(u => u.Id == userId);

                if (oldpassword == user.UserPassword)
                {
                    if (password == repassword)
                    {
                        using (md5 = MD5.Create())
                        {
                            _encrypt = new EnCryptography();
                            hashpass = _encrypt.GetMd5Hash(md5, repassword);
                        }
                        user.UserPassword = hashpass;
                        _context.Users.Update(user);
                        await _context.SaveChangesAsync();

                        // return RedirectToAction ("Index", "Home");
                    }
                }
            }
            return(RedirectToAction("Index", "Home"));
        }
        public async Task <IActionResult> Register([Bind("Email,UserPassword,FirstName,LastName,Phone,Address")] User user)
        {
            GetListNav();
            string hashpass;

            if (ModelState.IsValid)
            {
                var checkRegister = await _context.Users.FirstOrDefaultAsync(u => u.Email == user.Email);

                if (checkRegister == null)
                {
                    using (md5 = MD5.Create())
                    {
                        _encrypt = new EnCryptography();
                        hashpass = _encrypt.GetMd5Hash(md5, user.UserPassword);
                    }
                    user.Active       = 1;
                    user.Rank         = 0;
                    user.RoleId       = 1;
                    user.UserPassword = hashpass;
                    _context.Add(user);
                    await _context.SaveChangesAsync();

                    ViewBag.TitleRegisterSuccessfully = "Dang ky thanh cong!";
                    return(RedirectToAction(nameof(Login)));
                }
            }
            return(View());
        }