Пример #1
0
        public ActionResult Index(TaiKhoan taikhoan)
        {
            try
            {
                if (taikhoan.MatKhau.Equals(taikhoan.XacNhanMatKhau))
                {

                    taikhoan.NgayDangKy = DateTime.Now;
                    taikhoan.LoaiTaiKhoan = LoaiTaiKhoan.Member;
                    taikhoan.TrangThai = TrangThaiTaiKhoan.Active;

                    using (MD5 md5hash = MD5.Create())
                    {
                        string hash = GetMd5Hash(md5hash, taikhoan.MatKhau);
                        taikhoan.MatKhau = hash;
                    }

                    DataProvider dp = new DataProvider();

                    SqlParameter[] param = new SqlParameter[9];
                    param[0] = new SqlParameter("@email", SqlDbType.NVarChar);
                    param[0].Value = taikhoan.Email;

                    param[1] = new SqlParameter("@matkhau", SqlDbType.NVarChar);
                    param[1].Value = taikhoan.MatKhau;

                    param[2] = new SqlParameter("@maloaitaikhoan", SqlDbType.Int);
                    param[2].Value = taikhoan.LoaiTaiKhoan;

                    param[3] = new SqlParameter("@ten", SqlDbType.NVarChar);
                    param[3].Value = taikhoan.Ten;

                    param[4] = new SqlParameter("@ngaysinh", SqlDbType.DateTime);
                    if (taikhoan.NgaySinh == null )
                        param[4].Value = DBNull.Value;
                    else
                        param[4].Value = taikhoan.NgaySinh;

                    param[5] = new SqlParameter("@diachi", SqlDbType.NVarChar);
                    if (taikhoan.DiaChi == null)
                    {
                        param[5].Value = DBNull.Value;
                    }
                    else
                    {
                        param[5].Value = taikhoan.DiaChi;
                    }

                    param[6] = new SqlParameter("@dienthoai", SqlDbType.NVarChar);
                    if (taikhoan.DienThoai == null)
                    {
                        param[6].Value = DBNull.Value;
                    }
                    else { param[6].Value = taikhoan.DienThoai; }

                    param[7] = new SqlParameter("@ngaydangky", SqlDbType.DateTime);
                    param[7].Value = taikhoan.NgayDangKy;

                    param[8] = new SqlParameter("@trangthai", SqlDbType.Int);
                    param[8].Value = (int)taikhoan.TrangThai;

                    dp.ExecuteProcNonQuery("sp_DangKyTaiKhoan",ref param);
                    ViewBag.Result = true;
                    ViewBag.ErrorMessage = "";
                }
                else
                {
                    ViewBag.Result = false;
                    ViewBag.ErrorMessage = "Xác nhận mật khẩu không trùng khớp";
                }
            }
            catch (Exception ex)
            {
                ViewBag.Result = false;
                ViewBag.ErrorMessage = ex.Message;
            }

            return View("~/Views/Login/DangKy.cshtml");
        }