public void Luudonhang(Donhangtongquan a, string maKH, Giohang giohang)
        {
            try
            {
                using (Entities db = new Entities())
                {
                    DonHangKH dhkh = new DonHangKH();
                    dhkh.MaDH = RandomMa();
                    dhkh.MaKH = maKH;

                    dhkh.Diachi       = a.address;
                    dhkh.Dienthoai    = a.phoneNumber;
                    dhkh.Ghichu       = a.Note;
                    dhkh.NgayDatMua   = DateTime.Now;
                    dhkh.TinhTrangDH  = 1;
                    dhkh.Tongtien     = giohang.TinhtongtienCart();
                    dhkh.PhiVanChuyen = 0;

                    dhkh = db.DonHangKHs.Add(dhkh);
                    db.SaveChanges();

                    Luuchitietdonhang(giohang, db, dhkh.MaDH);
                }
            }
            catch (Exception e) { }
        }
 internal bool UpdateTinhTrang(string madh, int?tt)
 {
     if (tt == null)
     {
         return(false);
     }
     try
     {
         Entities  db = new Entities();
         DonHangKH dh = db.DonHangKHs.Find(madh);
         if (dh.TinhTrangDH == 4 || dh.TinhTrangDH == 3)
         {
             return(false);
         }
         if (dh.TinhTrangDH == 1)
         {
             if (tt == 2 || tt == 3)
             {
                 foreach (var item in dh.ChiTietDonHangs)
                 {
                     SanPhamModel spm = new SanPhamModel();
                     spm.UpdateSL(item.MaSP, item.SoLuong, false);
                 }
             }
         }
         if (dh.TinhTrangDH == 2)
         {
             if (tt == 4)
             {
                 foreach (var item in dh.ChiTietDonHangs)
                 {
                     SanPhamModel spm = new SanPhamModel();
                     spm.UpdateSL(item.MaSP, item.SoLuong, true);
                 }
             }
             if (tt == 1)
             {
                 return(false);
             }
         }
         string query = "update DonHangKH set TinhTrangDH = " + tt + " where MaDH ='" + madh + "'";
         db.Database.ExecuteSqlCommand(query);
         return(true);
     }
     catch (Exception e)
     {
         return(false);
     }
 }