public ActionResult Shop() { List <SanPham> shop = SanPhamAction.ListSanPham(); ViewBag.Shop = shop.OrderByDescending(a => a.masanpham); return(View()); }
public ActionResult ManageProduct() { var listproduct = SanPhamAction.ListSanPham(); ViewBag.Product = listproduct; return(View()); }
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()); } }
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()); } }
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")); } }
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()); } }
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")); } }
public ActionResult DeleteProduct(int keyword) { SanPhamAction.XoaSanPham(keyword); return(RedirectToAction("ManageProduct", "TMDT")); }