コード例 #1
0
        public ActionResult Shop()
        {
            List <SanPham> shop = SanPhamAction.ListSanPham();

            ViewBag.Shop = shop.OrderByDescending(a => a.masanpham);
            return(View());
        }
コード例 #2
0
        public ActionResult ManageProduct()
        {
            var listproduct = SanPhamAction.ListSanPham();

            ViewBag.Product = listproduct;

            return(View());
        }
コード例 #3
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());
     }
 }
コード例 #4
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());
     }
 }
コード例 #5
0
 public ActionResult InsertProduct(int matl, string tensanpham, double gia, HttpPostedFileBase myfile)
 {
     try
     {
         string _path = "";
         if (myfile.ContentLength > 0)
         {
             string _FileName = Path.GetFileName(myfile.FileName);
             _path = Path.Combine(Server.MapPath("~/UploadFiles"), _FileName);
             myfile.SaveAs(_path);
             SanPhamAction.addSanPham(matl, tensanpham, gia, _FileName);
         }
         return(RedirectToAction("ManageProduct", "TMDT"));
     }
     catch
     {
         return(RedirectToAction("ManageProduct", "TMDT"));
     }
 }
コード例 #6
0
 public ActionResult Home()
 {
     using (var db = new Context())
     {
         int accountid = Convert.ToInt32(Session["id"]);
         var feature   = db.ChiTietGioHang.Where(s => s.makh == accountid).ToList();
         int quantity  = 0;
         foreach (var a in feature)
         {
             quantity = quantity + a.soluong;
         }
         if (quantity != 0)
         {
             Session["QuantityCart"] = quantity;
         }
         else
         {
             Session["QuantityCart"] = 0;
         }
         ViewBag.Home = SanPhamAction.ListSanPham();
         return(View());
     }
 }
コード例 #7
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"));
     }
 }
コード例 #8
0
 public ActionResult DeleteProduct(int keyword)
 {
     SanPhamAction.XoaSanPham(keyword);
     return(RedirectToAction("ManageProduct", "TMDT"));
 }