public JsonResult ThemHoaDonSanPham(string HoTenNguoiNhan, string SoDienThoaiNguoiNhan, string DiaChiGiaoHang, string HinhThucThanhToan, string TrangThai, List <GioHangItem> cartModel) { DonDatHangModel donDatHangModel = new DonDatHangModel(); DonDatHang donDatHang = new DonDatHang(); if (Session["ADMIN_SESSION"] != null) { NhanVien nhanVien = new NhanVienModel().GetNhanVienByEmail(Session["ADMIN_SESSION"].ToString()); donDatHang.MaNV = nhanVien.MaNV; } donDatHang.HoTenNguoiNhan = HoTenNguoiNhan; donDatHang.SoDTGiaoHang = SoDienThoaiNguoiNhan; donDatHang.DiaChiNhanHang = DiaChiGiaoHang; donDatHang.HinhThucThanhToan = HinhThucThanhToan; donDatHang.TrangThaiDonSanPham = Convert.ToInt32(TrangThai); donDatHang.NgayTao = DateTime.Now; donDatHang.TrangThaiDonDichVu = 0; string MaDonHang = donDatHangModel.ThemDonDatHang(donDatHang); ChiTietDonDatModel chiTietDonDatModel = new ChiTietDonDatModel(); foreach (var item in cartModel) { ProductModel productModel = new ProductModel(); SanPham sp = productModel.GetSanPhamByMa(item.sanpham.MaSanPham); ChiTietDonDat chiTietDonDat = new ChiTietDonDat(); chiTietDonDat.MaDonDatHang = Convert.ToInt32(MaDonHang); chiTietDonDat.SoLuong = item.SoLuong; chiTietDonDat.MaSanPham = item.sanpham.MaSanPham; chiTietDonDat.Gia = sp.Gia; chiTietDonDatModel.ThemChiTietDonDat(chiTietDonDat); } donDatHangModel.CapNhatTongTien(Convert.ToInt32(MaDonHang)); string Message = "Thanh cong"; return(Json(Message, JsonRequestBehavior.AllowGet)); }
public ActionResult DatHang() { string makh = ""; string tennguoinhan = Request.Form["shipName"]; string sodienthoainhanhang = Request.Form["mobile"]; string diachi = Request.Form["address"]; DonDatHang donDatHang = new DonDatHang(); donDatHang.DiaChiNhanHang = diachi; donDatHang.SoDTGiaoHang = sodienthoainhanhang; donDatHang.HoTenNguoiNhan = tennguoinhan; donDatHang.HinhThucThanhToan = "COD"; if (Session["CART_SESSION"] != null) { if (Session["USER_SESSION"] != null) { var sdtkh = Session["USER_SESSION"].ToString(); int sdtkhnhan = Convert.ToInt32(sdtkh); Khachhang kh = new KhachHangModel().GetKhachHangBySDT(sdtkhnhan); makh = kh.MaKH.ToString(); } var cart = Session["CART_SESSION"]; var list = new List <GioHangItem>(); if (cart != null) { list = (List <GioHangItem>)cart; } if (makh != "" & makh != null) { donDatHang.MaKH = Convert.ToInt32(makh); } donDatHang.TrangThaiDonSanPham = 1; donDatHang.TrangThaiDonDichVu = 0; donDatHang.NgayTao = DateTime.Now; string madondathang = donDatHangModel.ThemDonDatHang(donDatHang); if (madondathang != null) { foreach (var item in list) { SanPham sanPham = new SanPham(); ProductModel productModel = new ProductModel(); ChiTietDonDat chiTietDonDat = new ChiTietDonDat(); chiTietDonDat.MaDonDatHang = Convert.ToInt32(madondathang); chiTietDonDat.SoLuong = item.SoLuong; chiTietDonDat.MaSanPham = item.sanpham.MaSanPham; chiTietDonDat.Gia = item.sanpham.Gia; chiTietDonDatModel.ThemChiTietDonDat(chiTietDonDat); } } donDatHangModel.CapNhatTongTien(Convert.ToInt32(madondathang)); } Session["CART_SESSION"] = null; Session["SLSP_SESSION"] = null; return(View()); }