コード例 #1
0
 public ActionResult UpdateProduct(int keyword)
 {
     using (var db = new Context())
     {
         var product = SanPhamAction.FindSanPham(keyword);
         ViewBag.Product    = product;
         ViewBag.Type       = db.TheLoai.Where(s => s.matl != product.matl).ToList();
         ViewBag.TypeUpdate = db.TheLoai.Where(s => s.matl == product.matl).FirstOrDefault();
         return(View());
     }
 }
コード例 #2
0
 public ActionResult ProductDetail(int productid)
 {
     using (var db = new Context())
     {
         var productdetail = SanPhamAction.FindSanPham(productid);
         var type          = db.TheLoai.Where(s => s.matl == productdetail.matl).FirstOrDefault();
         var description   = db.ChiTietSanPham.Where(s => s.masanpham == productdetail.masanpham).FirstOrDefault();
         ViewBag.Description   = description;
         ViewBag.Type          = type;
         ViewBag.ProductDetail = productdetail;
         ViewBag.ListProduct   = SanPhamAction.ListSanPham().OrderByDescending(s => s.masanpham);
         return(View());
     }
 }
コード例 #3
0
 public ActionResult addCart(int productid, int quantity)
 {
     using (var db = new Context())
     {
         if (checkLogin() == false)
         {
             var    cart    = SanPhamAction.FindSanPham(productid);
             double summary = quantity * cart.gia;
             //var appear = (from a in listcartdetail
             //              where a.masanpham == productid && a.isdeleted == false
             //              select a).ToList();
             if (Session["Cart"] == null)
             {
                 List <ChiTietGioHang> listcartdetail = new List <ChiTietGioHang>();
                 ChiTietGioHang        cartdetail     = new ChiTietGioHang {
                     mactgiohang = listcartdetail.Count + 1, makh = 1, masanpham = productid, soluong = quantity, thanhtien = summary
                 };
                 listcartdetail.Add(cartdetail);
                 Session["Cart"] = listcartdetail;
             }
             else
             {
                 List <ChiTietGioHang> listcartdetail = new List <ChiTietGioHang>();
                 listcartdetail = (List <ChiTietGioHang>)Session["Cart"];
                 var appear = (from a in listcartdetail
                               where a.masanpham == productid && a.isdeleted == false
                               select a).ToList();
                 if (appear.Count == 0)
                 {
                     ChiTietGioHang cartdetail = new ChiTietGioHang {
                         mactgiohang = listcartdetail.Count + 1, makh = 1, masanpham = productid, soluong = quantity, thanhtien = summary
                     };
                     listcartdetail.Add(cartdetail);
                     Session["Cart"] = listcartdetail;
                 }
                 else
                 {
                     foreach (var productappear in listcartdetail)
                     {
                         if (productappear.masanpham == productid)
                         {
                             productappear.soluong   = productappear.soluong + quantity;
                             productappear.thanhtien = productappear.thanhtien + summary;
                         }
                     }
                     Session["Cart"] = listcartdetail;
                 }
             }
         }
         else
         {
             int    userid  = Convert.ToInt32(Session["id"]);
             var    appear  = db.ChiTietGioHang.Where(s => s.masanpham == productid && s.makh == userid).ToList();
             var    cart    = SanPhamAction.FindSanPham(productid);
             double summary = cart.gia * quantity;
             if (appear.Count == 0)
             {
                 ChiTietGioHangAction.addCTGioHang(userid, productid, quantity, summary);
             }
             else
             {
                 ChiTietGioHangAction.DaTonTai(appear[0].mactgiohang, quantity, summary);
             }
         }
         return(RedirectToAction("Feature", "TMDT"));
     }
 }