public ActionResult Buy(string coupon, string phuongthucthanhtoan, string phuongthucvanchuyen)
        {
            using (var db = new Context())
            {
                if (checkLogin() == true)
                {
                    //string coupon = TempData["Coupon"].ToString();
                    int userid     = Convert.ToInt32(Session["id"]);
                    var timkiem    = db.Coupon.Where(s => s.makh == userid && s.tencoupon == coupon && s.check == false).FirstOrDefault();
                    var ctgiohang  = ChiTietGioHangAction.ListCTGioHang();
                    var ctgiohang1 = ctgiohang.Where(s => s.isdeleted == false && s.makh == userid);
                    if (timkiem != null)
                    {
                        //Cần sửa lại giá tiền nếu áp coupon
                        Coupon.CheckCoupon(timkiem.macoupon);
                        foreach (var valueindex in ctgiohang1)
                        {
                            LichSuMuaHang.addLSMuaHang(valueindex.makh, valueindex.masanpham, valueindex.soluong, valueindex.thanhtien);
                            ChiTietGioHangAction.XoaChiTietGioHang(valueindex.mactgiohang);
                        }
                    }
                    else
                    {
                        foreach (var valueindex in ctgiohang1)
                        {
                            LichSuMuaHang.addLSMuaHang(valueindex.makh, valueindex.masanpham, valueindex.soluong, valueindex.thanhtien);
                            ChiTietGioHangAction.XoaChiTietGioHang(valueindex.mactgiohang);
                        }
                    }
                }
                else
                {
                    Session.Remove("Cart");
                }

                return(RedirectToAction("Feature", "TMDT"));
            }
        }
 public ActionResult Login(string email, string password)
 {
     using (var db = new Context())
     {
         var login = (from a in db.KhachHang
                      where a.email == email && a.matkhau == password
                      select a).ToList();
         if (login.Count() != 0)
         {
             var quyen = (from a in db.KhachHang
                          where a.email == email && a.matkhau == password
                          select a.quyen).FirstOrDefault();
             var id = (from a in db.KhachHang
                       where a.email == email && a.matkhau == password
                       select a.makh).FirstOrDefault();
             var ten = (from a in db.KhachHang
                        where a.email == email && a.matkhau == password
                        select a.ten).FirstOrDefault();
             Session.Add("id", id.ToString());
             Session.Add("taikhoan", email);
             Session.Add("matkhau", password);
             Session.Add("quyen", quyen.ToString());
             Session.Add("ten", ten.ToString());
             var appear = (from a in db.GioHang
                           where a.makh == id
                           select a).ToList();
             var appearproduct = ChiTietGioHangAction.ListCTGioHang();
             if (Session["Cart"] != null)
             {
                 if (appear.Count == 0)
                 {
                     GioHangAction.addGioHang(id, ten);
                     List <ChiTietGioHang> addCart = new List <ChiTietGioHang>();
                     addCart = (List <ChiTietGioHang>)Session["Cart"];
                     foreach (var a in addCart)
                     {
                         foreach (var b in appearproduct)
                         {
                             if (a.mactgiohang != b.mactgiohang)
                             {
                                 ChiTietGioHangAction.addCTGioHang(id, a.masanpham, a.soluong, a.thanhtien);
                             }
                             else
                             {
                                 ChiTietGioHangAction.DaTonTai(a.mactgiohang, a.soluong, a.thanhtien);
                             }
                         }
                     }
                     Session.Remove("Cart");
                 }
                 else
                 {
                     List <ChiTietGioHang> addCart = new List <ChiTietGioHang>();
                     addCart = (List <ChiTietGioHang>)Session["Cart"];
                     ChiTietGioHang findproduct = new ChiTietGioHang();
                     foreach (var a in addCart)
                     {
                         foreach (var b in appearproduct)
                         {
                             if (b.makh == id && b.masanpham == a.masanpham)
                             {
                                 findproduct = new ChiTietGioHang {
                                     mactgiohang = b.mactgiohang, makh = b.makh, masanpham = b.masanpham, soluong = b.soluong, thanhtien = b.thanhtien
                                 };
                             }
                         }
                         if (findproduct.masanpham == 0)
                         {
                             ChiTietGioHangAction.addCTGioHang(id, a.masanpham, a.soluong, a.thanhtien);
                         }
                         else if (findproduct != null)
                         {
                             ChiTietGioHangAction.DaTonTai(findproduct.mactgiohang, a.soluong, a.thanhtien);
                         }
                     }
                     Session.Remove("Cart");
                 }
             }
             else
             {
                 if (appear.Count == 0)
                 {
                     GioHangAction.addGioHang(id, ten);
                 }
             }
             if (quyen.ToString() == "User")
             {
                 return(RedirectToAction("Home", "TMDT"));
             }
             else
             {
                 return(RedirectToAction("DashBoard", "TMDT"));
             }
         }
         else
         {
             TempData["ErrorLogin"] = "******";
             return(RedirectToAction("Login", "TMDT"));
         }
     }
 }