public async Task<ActionResult> Register([Bind(Include = "UserName, Password, ConfirmPassword, Email, FullName, PhoneNumber, RoleName")]RegisterViewModel model, string returnUrl)
        {
            UnitOfWork unitOfWork = new UnitOfWork();
            AspNetUser u = unitOfWork.AspNetUserRepository.Get(s => s.UserName == model.UserName).FirstOrDefault();
            if (u != null)
            {
                TempData["warningmessage"] = "Username đã tồn tại, xin hãy dùng Username khác!";

                if (!String.IsNullOrEmpty(returnUrl))
                {
                    return Redirect("../" + returnUrl);
                }
                else
                {
                    return RedirectToAction("Index", "Home");
                }
            }

            Jobseeker js = accountUnitOfWork.JobseekerRepository.Get(s => s.Email == model.Email).FirstOrDefault();
            Recruiter rc = accountUnitOfWork.RecruiterRepository.Get(s => s.Email == model.Email).FirstOrDefault();
            if (js != null || rc != null)
            {
                TempData["warningmessage"] = "Email đã tồn tại, xin hãy dùng Email khác!";

                if (!String.IsNullOrEmpty(returnUrl))
                {
                    return Redirect("../" + returnUrl);
                }
                else
                {
                    return RedirectToAction("Index", "Home");
                }
            }

            var user = new ApplicationUser() { UserName = model.UserName };
            var result = await UserManager.CreateAsync(user, model.Password);
            if (result.Succeeded)
            {
                var createdUser = await UserManager.FindAsync(model.UserName, model.Password);
                var roleResult = await UserManager.AddToRoleAsync(createdUser.Id, model.RoleName);
                if (model.RoleName == "Recruiter")
                {
                    Recruiter recruiter = new Recruiter();
                    recruiter.RecruiterID = createdUser.Id;
                    recruiter.Email = model.Email;
                    recruiter.IsDeleted = false;
                    unitOfWork.RecruiterRepository.Insert(recruiter);
                    unitOfWork.Save();

                    await SignInAsync(user, isPersistent: false);
                    TempData["warningmessage"] = "Đăng ký thành công, xin hãy cập nhật thông tin công ty!";
                    return RedirectToAction("Update", "CompanyInfo");
                }
                else
                {
                    Jobseeker jobseeker = new Jobseeker();
                    jobseeker.JobSeekerID = createdUser.Id;
                    jobseeker.Email = model.Email;
                    jobseeker.FullName = model.FullName;
                    jobseeker.PhoneNumber = model.PhoneNumber;
                    jobseeker.IsDeleted = false;
                    unitOfWork.JobseekerRepository.Insert(jobseeker);
                    unitOfWork.Save();

                    await SignInAsync(user, isPersistent: false);
                    TempData["successmessage"] = "Đăng ký thành công.";

                    if (!String.IsNullOrEmpty(returnUrl))
                    {
                        return Redirect("../" + returnUrl);
                    }
                    else
                    {
                        return RedirectToAction("Index", "Home");
                    }
                }
            }
            else
            {
                TempData["errormessage"] = "Đăng ký thất bại!";

                if (!String.IsNullOrEmpty(returnUrl))
                {
                    return Redirect("../" + returnUrl);
                }
                else
                {
                    return RedirectToAction("Index", "Home");
                }
            }
        }
        public ActionResult ActiveAccount(string UserName, string showoption)
        {
            UnitOfWork unitOfWork = new UnitOfWork();
            AspNetUser user = unitOfWork.AspNetUserRepository.Get(s => s.UserName == UserName).FirstOrDefault();

            if (user != null)
            {
                user.IsActive = true;
                unitOfWork.AspNetUserRepository.Update(user);
                unitOfWork.Save();

                TempData["successmessage"] = "Hoạt hóa tài khoản " + UserName + " thành công.";
            }
            else
            {
                TempData["errormessage"] = "Hoạt hóa tài khoản " + UserName + " thất bại!";
            }

            return RedirectToAction("List", "Account", new { showoption = showoption });
        }
        public async Task<ActionResult> ResetPassword(string emailAdress, string returnUrl)
        {
            if (!String.IsNullOrEmpty(emailAdress))
            {
                var chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
                var random = new Random();
                var newPassword = new string(Enumerable.Repeat(chars, 8)
                                             .Select(s => s[random.Next(s.Length)])
                                             .ToArray());
                string userId = "";

                try
                {
                    MailMessage mail = new MailMessage();
                    SmtpClient smtpClient = new SmtpClient("smtp.gmail.com");

                    UnitOfWork unitOfWork = new UnitOfWork();
                    mail.From = new MailAddress("*****@*****.**");
                    Jobseeker jobseeker = unitOfWork.JobseekerRepository.Get(s => s.Email == emailAdress && s.IsDeleted == false).FirstOrDefault();
                    Recruiter recruiter = unitOfWork.RecruiterRepository.Get(s => s.Email == emailAdress && s.IsDeleted == false).FirstOrDefault();
                    if (jobseeker != null){
                        mail.To.Add(jobseeker.Email);
                        userId = jobseeker.JobSeekerID;
                    }
                    else if (recruiter != null)
                    {
                        mail.To.Add(recruiter.Email);
                        userId = recruiter.RecruiterID;
                    }
                    else
                    {
                        TempData["errormessage"] = "Không tìm thấy Id tài khoản!";

                        if (!String.IsNullOrEmpty(returnUrl))
                        {
                            return Redirect("../" + returnUrl);
                        }
                        else
                        {
                            return RedirectToAction("Index", "Home");
                        }
                    }
                    mail.Subject = "[JSS] Thông báo mật khẩu mới";
                    mail.Body = "Mật khẩu của bạn đã được tạo mới là: " + newPassword;

                    smtpClient.Port = 587;
                    smtpClient.Credentials = new System.Net.NetworkCredential("*****@*****.**", "Kogarashi789");
                    smtpClient.EnableSsl = true;

                    smtpClient.Send(mail);
                }
                catch (Exception)
                {
                    TempData["errormessage"] = "Quá trình gửi mật khẩu mới gặp lỗi!";

                    if (!String.IsNullOrEmpty(returnUrl))
                    {
                        return Redirect("../" + returnUrl);
                    }
                    else
                    {
                        return RedirectToAction("Index", "Home");
                    }
                }

                await UserManager.RemovePasswordAsync(userId);
                IdentityResult result = await UserManager.AddPasswordAsync(userId, newPassword);
                if (result.Succeeded)
                {
                    TempData["successmessage"] = "Bạn hãy vào mail để xem mật khẩu mới.";
                }
                else
                {
                    TempData["errormessage"] = "Quá trình tạo mật khẩu mới gặp lỗi!";
                }
            }
            else
            {
                TempData["warningmessage"] = "Email trống!";
            }

            if (!String.IsNullOrEmpty(returnUrl))
            {
                return Redirect("../" + returnUrl);
            }
            else
            {
                return RedirectToAction("Index", "Home");
            }
        }
        public async Task<ActionResult> CreateAccount([Bind(Include = "UserName, Password, ConfirmPassword, RoleName")]RegisterViewModel model, string showoption)
        {
            if (!"Staff".Equals(model.RoleName) && !"Manager".Equals(model.RoleName))
            {
                TempData["errormessage"] = "Không được tạo tài khoản khác ngoài Staff và Manager!";
                return RedirectToAction("List", "Account", new { showoption = showoption });
            }

            UnitOfWork unitOfWork = new UnitOfWork();
            AspNetUser u = unitOfWork.AspNetUserRepository.Get(s => s.UserName == model.UserName).FirstOrDefault();
            if (u != null)
            {
                TempData["errormessage"] = "Username " + model.UserName + " đã tồn tại!";
                return RedirectToAction("List", "Account", new { showoption = showoption });
            }

            var user = new ApplicationUser() { UserName = model.UserName };
            var result = await UserManager.CreateAsync(user, model.Password);
            if (result.Succeeded)
            {
                var createdUser = await UserManager.FindAsync(model.UserName, model.Password);
                var roleResult = await UserManager.AddToRoleAsync(createdUser.Id, model.RoleName);
                if (model.RoleName == "Staff")
                {
                    Staff staff = new Staff();
                    staff.StaffID = createdUser.Id;
                    staff.IsDeleted = false;
                    unitOfWork.StaffRepository.Insert(staff);
                    unitOfWork.Save();

                    TempData["successmessage"] = "Tạo tài khoản " + model.UserName + " với role Staff thành công.";
                }
                else
                {
                    Manager manager = new Manager();
                    manager.ManagerID = createdUser.Id;
                    manager.IsDeleted = false;
                    unitOfWork.ManagerRepository.Insert(manager);
                    unitOfWork.Save();

                    TempData["successmessage"] = "Tạo tài khoản " + model.UserName + " với role Manager thành công.";
                }
            }
            else
            {
                TempData["errormessage"] = "Tạo tài khoản " + model.UserName + " thất bại!";
            }

            return RedirectToAction("List", "Account", new { showoption = showoption });
        }
        public void SendEmail(string receiverUsername, string title, string content)
        {
            if (!String.IsNullOrEmpty(receiverUsername)
                && !String.IsNullOrEmpty(title)
                && !String.IsNullOrEmpty(content))
            {
                AspNetUser user = this.AspNetUserRepository.Get(s => s.UserName == receiverUsername).FirstOrDefault();
                if (user == null)
                {
                    return;
                }

                try
                {
                    MailMessage mail = new MailMessage();
                    SmtpClient smtpClient = new SmtpClient("smtp.gmail.com");

                    UnitOfWork unitOfWork = new UnitOfWork();
                    mail.From = new MailAddress("*****@*****.**");
                    Jobseeker jobseeker = unitOfWork.JobseekerRepository.GetByID(user.Id);
                    Recruiter recruiter = unitOfWork.RecruiterRepository.GetByID(user.Id);
                    if (jobseeker != null)
                    {
                        mail.To.Add(jobseeker.Email);
                    }
                    else if (recruiter != null)
                    {
                        mail.To.Add(recruiter.Email);
                    }
                    else
                    {
                        return;
                    }
                    mail.Subject = "[JSS] " + title;
                    mail.IsBodyHtml = true;
                    mail.Body = content;

                    smtpClient.Port = 587;
                    smtpClient.Credentials = new System.Net.NetworkCredential("*****@*****.**", "Kogarashi789");
                    smtpClient.EnableSsl = true;

                    smtpClient.Send(mail);
                }
                catch (Exception)
                {
                    return;
                }
            }
        }