public ActionResult EditProduct(int id) { DropDownListCategory(); var model = new ProductADO().GetProductId(id); return(View(model)); }
/****************************************************************/ /* Function Name : ListProductName() * /* Function Content: List product name * /* Param : sKeyword(i) string key words * /* Return : Json : return list product name in Json Jquery format * /* Create : T.Khai 2020/12/23 * /* Update : * /* Comment : Fife jquery: /Contents/js/JsFileController/search-autocomplete * /****************************************************************/ public JsonResult ListProductName(string sKeyword) { var productName = new ProductADO().GetProductName(sKeyword); return(Json(new { data = productName, status = true }, JsonRequestBehavior.AllowGet)); }
// GET: Admin/Product public ActionResult Index(int page = 1, int pageSize = 3) { int totalRecord = 0; var model = new ProductADO().GetAllProductsForAdmin(ref totalRecord, page, pageSize); // Tổng bản ghi Lấy từ DB / số sp muốn hiển thị int totalPage = 0; totalPage = (int)Math.Ceiling((double)(totalRecord / pageSize)); int displayMaxPages = 6; ViewBag.DisplayMaxPages = displayMaxPages; ViewBag.StartIndex = page; ViewBag.TotalPage = totalPage; ViewBag.Next = page + 1; ViewBag.Prev = page - 1; return(View(model)); }
// totalItems (required) - the total number of items to be paged // currentPage (optional) - the current active page, default to first page // pageSize (optional) - the number of items per page, defaults to 10 // maxPages (optional) - the maximum number of page navigation link to display, defaul to 7 public ActionResult ListAllProducts(int nPage = 1, int nPageSize = 4)// pageSize = productsPerPage { int nTotalRecord = 0; var model = new ProductADO().GetAllProducts(ref nTotalRecord, nPage, nPageSize); ViewBag.TotalRecord = nTotalRecord; ViewBag.StartIndex = nPage; int totalPage = 0; int displayMaxPages = 6; // Tổng trang của số bản ghi / số lượng sp hiển thị totalPage = (int)Math.Ceiling((double)nTotalRecord / nPageSize); // Math.Ceiling(double a) -> ham lam tron so len ViewBag.TotalPage = totalPage; ViewBag.DisplayMaxPages = displayMaxPages; ViewBag.Next = nPage + 1; ViewBag.Prev = nPage - 1; return(View(model)); }
public ActionResult AddProduct(product entity) { if (ModelState.IsValid) { entity.created_date = DateTime.Now; entity.status = true; var result = new ProductADO().Insert(entity); if (result > 0) { SetAlert("Thêm mới thành công!", "success"); return(Redirect("/Admin/quan-ly-san-pham")); } else { ModelState.AddModelError("", "Thêm mới không thành công!"); } } DropDownListCategory(); return(View()); }
public ActionResult EditProduct(product prdEntity) { if (ModelState.IsValid) { prdEntity.created_date = DateTime.Now; prdEntity.status = true; var result = new ProductADO().Update(prdEntity); if (result) { SetAlert("Cập nhật sản phẩm thành công!", "success"); return(Redirect("/Admin/quan-ly-san-pham")); } else { ModelState.AddModelError("", "Cập nhật không thành công!"); } } DropDownListCategory(); return(View()); // return Redirect("/Admin/quan-ly-san-pham"); }
public ActionResult AddItems(int productId, int quantity) { // get product id var product = new ProductADO().GetProductId(productId); var cart = Session[SessionConst.CART_SESSION]; if (cart != null) // giỏ hàng đã tồn tại -> cộng số lượng { var listItems = (List <CartModel>)cart; if (listItems.Exists(x => x.Product.product_id == productId)) { foreach (var item in listItems) { if (item.Product.product_id == productId) { item.Quantity += quantity; } } } else // giỏ hàng đã tồn tại nhưng khác sản phẩm -> tạo mới { var item = new CartModel(); item.Product = product; item.Quantity = quantity; listItems.Add(item); } } else // giỏ hàng chưa tồn tại -> tạo mới { var item = new CartModel(); item.Product = product; item.Quantity = quantity; var listItems = new List <CartModel>(); listItems.Add(item); Session[SessionConst.CART_SESSION] = listItems; // Assign to session } return(Redirect(Request.UrlReferrer.ToString())); }
/****************************************************************/ /* Function Name : ViewProductDetails() * /* Function : View product details * /* Param : nPrdId(i) Product id to return * /* Return : model : return a record (1 hàng) * /* Create : T.Khai 2020/12/23 * /* Update : * /* Comment : * /****************************************************************/ public ActionResult ViewProductDetails(int nPrdId) { var model = new ProductADO().GetProductId(nPrdId); return(View(model)); }
/****************************************************************/ /* Function Name : ListProductsByCategory() * /* Function : List of products by category * /* Param : nCategoryId(i) category id to return the product list * /* Return : model : return a product objet * /* Create : T.Khai 2021/01/11 * /* Update : * /* Comment : * /****************************************************************/ public ActionResult ListProductsByCategory(int nCategoryId) { var model = new ProductADO().GetListProductsByCategoryId(nCategoryId); return(View(model)); }
public ActionResult _ListDiscountProductsPartial() { var model = new ProductADO().GetListDiscountProducts(8); return(PartialView(model)); }
public ActionResult _ListRelatedProductsPartial(int nPrdId) { var listRecords = new ProductADO().GetListRelatedProducts(nPrdId); return(PartialView(listRecords)); }