// public ActionResult DatHang(FormCollection f) { // Thêm đơn hàng DONDATHANG ddh = new DONDATHANG(); KHACHHANG kh = (KHACHHANG)Session["TaiKhoan"]; List <GioHang> gh = Laygiohang(); ddh.MaKH = kh.MaKH; ddh.Ngaydat = DateTime.Now; var ngaygiao = String.Format("{0:MM/dd/yyyy}", f["NgayGiao"]); ddh.Ngaygiao = DateTime.Parse(ngaygiao); ddh.Tinhtranggiaohang = false; ddh.Dathanhtoan = false; data.DONDATHANGs.InsertOnSubmit(ddh); data.SubmitChanges(); // Thêm chi tiết đơn hàng foreach (var item in gh) { CHITIETDATHANG ctdh = new CHITIETDATHANG(); ctdh.MaDonHang = ddh.MaDonHang; ctdh.MaCa = item.iMaca; ctdh.SoLuong = item.iSoluong; ctdh.DonGia = (decimal)item.dDongia; data.CHITIETDATHANGs.InsertOnSubmit(ctdh); } data.SubmitChanges(); Session["GioHang"] = null; return(RedirectToAction("Xacnhandonhang", "GioHang")); }
public ActionResult DatHang(FormCollection collection) { //Them Don hang DATHANG ddh = new DATHANG(); KHACHHANG kh = (KHACHHANG)Session["Taikhoan"]; List <GioHang> gh = Laygiohang(); ddh.Makh = kh.Makh; ddh.Ngaydathang = DateTime.Now; var ngaygiao = String.Format("{0:MM/dd/yyyy}", collection["Ngaygiao"]); ddh.Ngaygiahang = (ngaygiao).ToString(); ddh.Dagiaohang = false; ddh.Dathanhtoan = false; data.DATHANGs.InsertOnSubmit(ddh); data.SubmitChanges(); //Them chi tiet don hang foreach (var item in gh) { CHITIETDATHANG ctdh = new CHITIETDATHANG(); ctdh.Madh = ddh.Madh; ctdh.Masp = item.iMasach; ctdh.Soluong = item.iSoluong; ctdh.Gia = (decimal)item.dDongia; data.CHITIETDATHANGs.InsertOnSubmit(ctdh); } data.SubmitChanges(); Session["GioHang"] = null; return(RedirectToAction("Xacnhandonhang", "GioHang")); }
public bool UpdateCTDH(ChiTietDatHangViewModel model) { CHITIETDATHANG CTDHExit = context.CHITIETDATHANGs.FirstOrDefault(t => t.TrangThai != false && t.Id_ChiTietDatHang == model.MaChiTiet); if (CTDHExit == null) { return(false); } CTDHExit.SoLuong = model.SoLuong; CTDHExit.ThanhTien = model.SoLuong * CTDHExit.GiaBan; var datHang = context.DATHANGs .Include(t => t.CHITIETDATHANGs) .FirstOrDefault(t => t.Id_DatHang == CTDHExit.Id_DatHang && t.TrangThai == 1); if (datHang == null) { return(false); } //tinh tong tien var newTongTien = datHang.CHITIETDATHANGs.Where(t => t.TrangThai != false). Sum(t => t.SoLuong * t.GiaBan); //update tong tien datHang.TongTien = newTongTien; //save context.SaveChanges(); return(true); }
public bool DeleteDetail(int maCTDH) { CHITIETDATHANG CTDHExit = context.CHITIETDATHANGs.FirstOrDefault(t => t.TrangThai != false && t.Id_ChiTietDatHang == maCTDH); if (CTDHExit == null) { return(false); } CTDHExit.TrangThai = false; // update tong tien //lay dat hang var datHang = context.DATHANGs .Include(t => t.CHITIETDATHANGs) .FirstOrDefault(t => t.Id_DatHang == CTDHExit.Id_DatHang && t.TrangThai == 1); if (datHang == null) { return(false); } //tinh tong tien var newTongTien = datHang.CHITIETDATHANGs.Where(t => t.TrangThai != false). Sum(t => t.SoLuong * t.GiaBan); //update tong tien datHang.TongTien = newTongTien; //save context.SaveChanges(); return(true); }
public ActionResult fillFormCustomer(string id, bool Accumulated) { List <ProductCart> productCarts = GetProductCarts(); var strimId = id.Trim(','); var listHadCheck = strimId.Split(',').Select(int.Parse).ToList(); //lấy ra sản phẩm trong giỏ hàng từ các sản phẩm đã chọn var products = productCarts.Where(x => listHadCheck.Contains(x.Id_SanPham)); // tổng tiền trong giổ hàng var sumTotal = products.Sum(x => x.soluong * x.giagiam); var customerlogin = SessionUser.GetSession(); var customer = db.KHACHHANGs.Where(x => x.Id_KhachHang == customerlogin.Id).FirstOrDefault(); var address = db.DIACHIs.Where(x => x.Id_KhachHang == customer.Id_KhachHang && x.TrangThai == true).FirstOrDefault(); DATHANG orderForm = new DATHANG { NgayDat = DateTime.Now, TrangThai = 1, DiaChiGiao = address.DiaChi, SoDienThoai = address.SoDienThoai, Id_KhachHang = customer.Id_KhachHang, TenNguoiNhan = address.TenKhachHang, // 50 tiền ship TongTien = sumTotal + 50 }; var aNewOder = db.DATHANGs.Add(orderForm); orderForm.Id_DatHang = aNewOder.Id_DatHang; // nếu nó có check thì lưu thêm cột giảm giá if (Accumulated == true) { orderForm.TongTienSauGiamGia = orderForm.TongTien - (double.Parse(customer.DiemTichLuy.ToString()) * 1000); orderForm.DiemTichLuy = customer.DiemTichLuy; customer.DiemTichLuy = 0; db.Entry(customer).State = System.Data.Entity.EntityState.Modified; db.SaveChanges(); } foreach (var product in products) { CHITIETDATHANG detailOrder = new CHITIETDATHANG(); detailOrder.Id_DatHang = aNewOder.Id_DatHang; detailOrder.Id_SanPham = product.Id_SanPham; detailOrder.SoLuong = product.soluong; detailOrder.GiaBan = product.giagiam; detailOrder.ThanhTien = product.soluong * product.giagiam; detailOrder.TrangThai = true; db.CHITIETDATHANGs.Add(detailOrder); } db.SaveChanges(); return(RedirectToAction("succesBill", "PayForBill", new { idDatHang = orderForm.Id_DatHang })); }
public bool Insert(CHITIETDATHANG ctdh) { try { db.CHITIETDATHANGs.Add(ctdh); db.SaveChanges(); return(true); } catch (Exception) { return(false); } }
/// <summary> /// Thanh toán /// </summary> /// <returns></returns> public ActionResult Checkout() { if (Session[CommonContants.USER_SESSION] == null) { return(RedirectToAction("Login", "Account")); } var lsCart = (List <WebBanQuanAo.Models.CartModel>)Session[CommonContants.CART_SESSION]; if (lsCart == null) { return(RedirectToAction("Index", "Home")); } try { var us = (UserLogin)Session[CommonContants.USER_SESSION]; var DDHdao = new DonDatHangDao(); var dondathang = new DONDATHANG(); dondathang.makhachhang = us.UserID; dondathang.noigiaohang = new KhachHangDao().ViewDetail(us.UserID).diachi; dondathang.ngaydathang = DateTime.Now; int res = new DonDatHangDao().Insert(dondathang); var CTHDdao = new ChiTietDatHangDao(); foreach (var item in lsCart) { var ctdh = new CHITIETDATHANG() { sohoadon = res, mahang = item.SanPham.ma, giaban = (double)item.SanPham.giaban, soluong = item.SoLuong }; if (!CTHDdao.Insert(ctdh)) { ModelState.AddModelError("", "Lõi hệ thống"); //break; } } Session[CommonContants.CART_SESSION] = null; Session[CommonContants.COUNT_CART_SESSION] = 0; return(Redirect("/hoan-thanh")); } catch (Exception) { return(Redirect("/loi")); } }
public bool Update(CHITIETDATHANG ctdh) { try { var hdct = db.CHITIETDATHANGs.SingleOrDefault(x => x.sohoadon == ctdh.sohoadon && x.mahang == ctdh.mahang); var mh = db.MATHANGs.SingleOrDefault(x => x.ma == hdct.mahang); hdct.giaban = (double)mh.giaban; hdct.soluong = ctdh.soluong; db.SaveChanges(); return(true); } catch (Exception) { return(false); } }