public ActionResult OrderStock(string MaKH, string MaH, string SoLuong)
        {
            KhachHang skhachHang = Session["khachHang"] as KhachHang;

            if (skhachHang == null || db.KhachHangs.Where(d => d.MaKH == skhachHang.MaKH && d.DaXoa == false).FirstOrDefault() == null)
            {
                return(RedirectToAction("Index", "Login"));
            }
            if (SoLuong == "")
            {
                ViewBag.Loi = "Chưa nhập số lượng";
            }
            else
            {
                int        sl         = int.Parse(SoLuong);
                Hang       hang       = db.Hangs.Where(d => d.MaH == MaH).FirstOrDefault();
                DonHangDat donHangDat = db.DonHangDats.Where(d => d.MaKH == MaKH && d.TrangThai == "Đang đặt" && d.DaXoa == false).Include(d => d.HangDonHangDats).FirstOrDefault();
                if (donHangDat != null)
                {
                    HangDonHangDat hangDonHangDat = db.HangDonHangDats.Where(d => d.MaDHD == donHangDat.MaDHD && d.MaH == MaH).FirstOrDefault();
                    if (hangDonHangDat != null)
                    {
                        hangDonHangDat.SoLuong += sl;
                    }
                    else
                    {
                        HangDonHangDat hangDonHangDatMoi = new HangDonHangDat();
                        hangDonHangDatMoi.MaDHD   = donHangDat.MaDHD;
                        hangDonHangDatMoi.MaH     = MaH;
                        hangDonHangDatMoi.SoLuong = sl;
                        db.HangDonHangDats.Add(hangDonHangDatMoi);
                    }
                    ViewBag.SoLuongHangDat = donHangDat.HangDonHangDats.Count() + 1;
                }
                else
                {
                    DonHangDat donHangDatMoi = new DonHangDat();
                    int        count         = db.DonHangDats.Count() + 1;
                    donHangDatMoi.MaDHD      = "DHD" + count.ToString();
                    donHangDatMoi.MaKH       = MaKH;
                    donHangDatMoi.NgayBatDau = DateTime.Now;
                    donHangDatMoi.TrangThai  = "Đang đặt";

                    HangDonHangDat hangDonHangDatMoi = new HangDonHangDat();
                    hangDonHangDatMoi.MaDHD   = donHangDatMoi.MaDHD;
                    hangDonHangDatMoi.MaH     = MaH;
                    hangDonHangDatMoi.SoLuong = sl;
                    db.DonHangDats.Add(donHangDatMoi);
                    db.HangDonHangDats.Add(hangDonHangDatMoi);
                    ViewBag.SoLuongHangDat = 1;
                }
                db.SaveChanges();
            }
            return(RedirectToAction("Index", "Home"));
        }
        public ActionResult DeleteOrder(string MaDHD, string MaH)
        {
            KhachHang skhachHang = Session["khachHang"] as KhachHang;

            if (skhachHang == null || db.KhachHangs.Where(d => d.MaKH == skhachHang.MaKH && d.DaXoa == false).FirstOrDefault() == null)
            {
                return(RedirectToAction("Index", "Login"));
            }
            HangDonHangDat hangDonHangDat = db.HangDonHangDats.Where(d => d.MaDHD == MaDHD && d.MaH == MaH).FirstOrDefault();

            if (hangDonHangDat != null)
            {
                db.HangDonHangDats.Remove(hangDonHangDat);
                db.SaveChanges();
            }
            return(RedirectToAction("Orders"));
        }