public static bool ThemHoaDon(HoaDon hoaDon)
 {
     try
     {
         db.HoaDons.AddObject(hoaDon);
         return db.SaveChanges() > 0;
     }
     catch
     {
         return false;
     }
 }
        public ActionResult ThanhToan()
        {
            if (!Request.IsAuthenticated)
            {
                throw new Exception();
            }
            else
            {
                GioHangDangMuaModel model = GioHangDangMuaModel.LayGioHang(this);

                if (model.CacGoiHang.Count <= 0)
                {
                    return Json(new
                    {
                        Flag = "Unsuccess"
                    });
                }

                HoaDon hoaDon = new HoaDon();
                hoaDon.TenTaiKhoan = User.Identity.Name;
                hoaDon.NgayTao = DateTime.Now;
                hoaDon.BiXoa = false;

                model.TaoHoaDon(hoaDon);

                bool thanhCong = HoaDonBLL.ThemHoaDon(hoaDon);
                if (thanhCong)
                {
                    return Json(new
                    {
                        Flag = "Success",
                        Total = String.Format("{0:0,0} VND", hoaDon.TongTien)
                    });
                }
                else
                {
                    return Json(new
                    {
                        Flag = "Unsuccess"
                    });
                }
            }
        }
 /// <summary>
 /// Deprecated Method for adding a new object to the HoaDons EntitySet. Consider using the .Add method of the associated ObjectSet&lt;T&gt; property instead.
 /// </summary>
 public void AddToHoaDons(HoaDon hoaDon)
 {
     base.AddObject("HoaDons", hoaDon);
 }
 /// <summary>
 /// Create a new HoaDon object.
 /// </summary>
 /// <param name="maHoaDon">Initial value of the MaHoaDon property.</param>
 public static HoaDon CreateHoaDon(global::System.Int32 maHoaDon)
 {
     HoaDon hoaDon = new HoaDon();
     hoaDon.MaHoaDon = maHoaDon;
     return hoaDon;
 }
        public void TaoHoaDon(HoaDon hoaDon)
        {
            float tongTien = 0;

            foreach (var item in CacGoiHang)
            {
                var chiTietHoaDon = new ChiTietHoaDon()
                {
                    BiXoa = false,
                    GiaTienHienTai = item.SanPhamDuocChon.Gia,
                    MaSanPham = item.SanPhamDuocChon.MaSanPham,
                };
                hoaDon.ChiTietHoaDons.Add(chiTietHoaDon);
                tongTien += float.Parse(item.SanPhamDuocChon.Gia.ToString()) * item.SoLuong;
            }

            hoaDon.TongTien = tongTien;

            LamTrongGioHang();
        }