public JsonResult JSPayCheck(FormCollection form) { JsonResult js = new JsonResult(); bool isNumeric = true; string finame = form["finame"]; string miname = form["miname"]; string laname = form["laname"]; string add1 = form["add1"]; string add2 = form["add2"]; string country = form["country"]; string state = form["state"]; string city = form["city"]; string phone = form["phone"]; if (string.IsNullOrEmpty(finame) || string.IsNullOrEmpty(laname) || string.IsNullOrEmpty(add1) || string.IsNullOrEmpty(country) || string.IsNullOrEmpty(state) || string.IsNullOrEmpty(city) || string.IsNullOrEmpty(phone)) { js.Data = new { status = "EMPTY" }; } else { foreach (char c in phone) { if (!Char.IsNumber(c)) { isNumeric = false; break; } } if (isNumeric == false) { js.Data = new { status = "ERRPHONE" }; } else { if (phone.Length != 10) { js.Data = new { status = "ERRPHONE" }; } else { string address = add1 + " " + add2 + " " + state + " " + city + " " + country; string name = finame + " " + miname + " " + laname; if (Session["Cart"] == null) { Response.Redirect("/Product/Product/1"); } Code code = new Code(); List <CartItem> giohang = Session["Cart"] as List <CartItem>; if (giohang.Count() == 0) { Response.Redirect("/Product/Product/1"); } bool status = true; foreach (CartItem item in giohang) { if (item.SoLuong > code.Get_ThietBi().FirstOrDefault(m => m.MaThietBi == item.SanPhamID).SoLuong) { status = false; item.SoLuong = code.Get_ThietBi().FirstOrDefault(m => m.MaThietBi == item.SanPhamID).SoLuong; } } if (status == true) { if (Session["User"] == null) { Response.Redirect("/Login/Login"); } else { tbl_KhachHang u = (tbl_KhachHang)Session["User"]; tbl_HoaDon hd = new tbl_HoaDon(); hd.MaKhachHang = u.MaKhachHang; hd.NgayLap = DateTime.Now.Day + "/" + DateTime.Now.Month + "/" + DateTime.Now.Year; hd.MaTrangThaiDonHang = 2; hd.DiaChiNhan = address; hd.NguoiNhan = name; hd.SDT = int.Parse(phone); hd.TongTien = giohang.Sum(m => m.ThanhTien); hd.TrangThaiThanhToan = 2; code.AddObject(hd); foreach (CartItem item in giohang) { tbl_ChiTietHoaDon cthd = new tbl_ChiTietHoaDon(); cthd.MaHoaDon = hd.MaHoaDon; cthd.MaThietBi = item.SanPhamID; cthd.SoLuong = item.SoLuong; cthd.ThanhTien = item.ThanhTien; cthd.DonGia = item.DonGia; code.AddObject(cthd); code.Save(); tbl_ThietBi tb = code.Get_ThietBi().FirstOrDefault(m => m.MaThietBi == item.SanPhamID); tb.SoLuong = tb.SoLuong - item.SoLuong; code.Save(); } code.Save(); Session.Remove("Cart"); js.Data = new { status = "OK" }; } } else { js.Data = new { status = "ER" }; } } } } return(Json(js, JsonRequestBehavior.AllowGet)); }
public JsonResult JSDangKi(FormCollection data) { if (data["rtk"] == null) { Response.Redirect("/Home/Index"); } Code code = new Code(); string tk = data["rtk"]; string mk = data["rmk"]; string rmk = data["remk"]; string email = data["remail"]; string ten = data["rten"]; JsonResult js = new JsonResult(); if (String.IsNullOrEmpty(tk) || String.IsNullOrEmpty(mk) || String.IsNullOrEmpty(rmk) || String.IsNullOrEmpty(email)) { js.Data = new { status = "ERR" }; } else { if (mk != rmk) { js.Data = new { status = "ERMK" }; } else { var RexPW = new Regex(@"^(?=.*\d)(?=.*[A-Z])(?=.*\W).{8,32}$"); var RexUID = new Regex(@"^[a-z_][a-z0-9_\.\s]{8,32}$"); var RexEmail = new Regex(@"^[a-z][a-z0-9_\.]{4,31}@[a-z0-9]{2,}(\.[a-z0-9]{2,4}){1,2}$"); if (!RexPW.IsMatch(mk)) { js.Data = new { status = "ER" }; } else if (!RexUID.IsMatch(tk)) { js.Data = new { status = "ER" }; } else if (!RexEmail.IsMatch(email)) { js.Data = new { status = "ER" }; } else if (ten.Length < 2) { js.Data = new { status = "ER" }; } else { if (code.Get_KhachHang(tk) != null) { js.Data = new { status = "ERTK" }; } else { tbl_KhachHang kh = new tbl_KhachHang(); kh.TaiKhoan = tk; kh.MatKhau = Encryptor.MD5Hash(mk); kh.Email = email; kh.Ten = ten; code.AddObject(kh); code.Save(); js.Data = new { status = "OK" }; } } } } return(Json(js, JsonRequestBehavior.AllowGet)); }