public static bool TaoTaiKhoan(createUserViewModel vm)
        {
            if (KiemTraEmailTonTai(vm.Email))
            {
                return(false);
            }

            Entities entities = new Entities();
            TaiKhoan TaiKhoan = new TaiKhoan();

            TaiKhoan.Ten         = vm.HoTen;
            TaiKhoan.TenDangNhap = vm.Email;
            TaiKhoan.MatKhau     = SecurePasswordHasher.Hash(vm.MatKhau);

            foreach (int MaNhom in vm.MaNhom.OrEmptyIfNull())
            {
                Nhom nhom = entities.Nhoms.Where(p => p.id == MaNhom).First();
                TaiKhoan.Nhom.Add(nhom);
            }

            entities.TaiKhoan.Add(TaiKhoan);
            entities.SaveChanges();

            return(true);
        }
        // POST: api/User
        public string Post(createUserViewModel viewModel)
        {
            var Session = HttpContext.Current.Session;

            if (!Session.isAdminSession())
            {
                return("");
            }

            string Error = ValidateViewModel(viewModel);

            if (Error == "")
            {
                if (string.IsNullOrEmpty(viewModel.MatKhau))
                {
                    return(JsonConvert.
                           SerializeObject(new ResultViewModel(
                                               "Mật khẩu không được để trống",
                                               "Đã xảy ra lỗi trong quá trình tạo tài khoản")));
                }

                if (!Helper.KiemTraHopLeMatKhau(viewModel.MatKhau))
                {
                    return(JsonConvert.
                           SerializeObject(new ResultViewModel(
                                               "Mật khẩu phải có kí tự viết hoa, tối thiểu 8 kí tự",
                                               "Đã xảy ra lỗi trong quá trình tạo tài khoản")));
                }

                if (string.IsNullOrEmpty(viewModel.MatKhau))
                {
                    return(JsonConvert.
                           SerializeObject(new ResultViewModel(
                                               "Mật khẩu nhập lại không được để trống",
                                               "Đã xảy ra lỗi trong quá trình tạo tài khoản")));
                }

                if (!Authentication_DAO.TaoTaiKhoan(viewModel))
                {
                    return(JsonConvert.
                           SerializeObject(new ResultViewModel(
                                               "Email của tài khoản này đã tồn tại rồi",
                                               "Đã xảy ra lỗi trong quá trình tạo tài khoản")));
                }
            }

            return(Error);
        }