public ActionResult Category(long cateId, int page = 1) { var category = new MoProductCategoryController().ViewDetail(cateId); ViewBag.Category = category; int totalRecord = 0; int pageSize = 12; var model = new MoProductController().ListByCategoryId(cateId, ref totalRecord, page, pageSize); ViewBag.Total = totalRecord; ViewBag.Page = page; int maxPage = 5; int totalPage = 0; totalPage = (int)Math.Ceiling((double)(totalRecord / pageSize)); ViewBag.TotalPage = totalPage; ViewBag.MaxPage = maxPage; ViewBag.First = 1; ViewBag.Last = totalPage; ViewBag.Next = page + 1; ViewBag.Prev = page - 1; return(View(model)); }
public JsonResult LoadImages(long id) { var productController = new MoProductController(); var product = productController.ViewDetail(id); var images = product.MoreImages; try { XElement xImages = XElement.Parse(images); List <string> listImagesReturn = new List <string>(); foreach (XElement element in xImages.Elements()) { listImagesReturn.Add(element.Value); } return(Json(new { data = listImagesReturn }, JsonRequestBehavior.AllowGet)); } catch { return(Json(new { status = false }, JsonRequestBehavior.AllowGet)); } }
// GET: Admin/Product public ActionResult Index(string searchString, int page = 1, int pageSize = 5) { var productController = new MoProductController(); var model = productController.ListAllPaging(searchString, page, pageSize); return(View(model)); }
public ActionResult Edit(long id) { var productController = new MoProductController(); var product = productController.GetByID(id); SetViewBag(product.CategoryID); return(View()); }
public JsonResult ChangeStatus(long id) { var result = new MoProductController().ChangeStatus(id); return(Json(new { status = result })); }
public JsonResult ListName(string q) { var data = new MoProductController().ListName(q); return(Json(new { data = data, status = true }, JsonRequestBehavior.AllowGet)); }
// GET: Home public ActionResult Index() { ViewBag.Slides = new MoSlideController().ListAll(); var productController = new MoProductController(); ViewBag.NewProducts = productController.ListNewProduct(4); ViewBag.ListAllProduct = productController.listAllProduct(); var contentController = new MoContentController().ListAll(); return(View(contentController)); }
public ActionResult Create(Product model) { if (ModelState.IsValid) { var productController = new MoProductController(); long res = productController.CreateProduct(model.Name, model.CategoryID, model.Code, model.MetaTitle, model.Description, model.Image, model.Price, model.PromotionPrice, model.Quantity, model.Detail, model.CreatedBy, model.Status); model.CreatedDate = DateTime.Now; if (res > 0) { return(RedirectToAction("Index")); } } SetViewBag(); return(View()); }
public ActionResult Edit(Product product) { var productController = new MoProductController(); var result = productController.Update(product); if (result) { SetAlert("Sửa product thành công", "success"); return(RedirectToAction("Index", "Product")); } else { ModelState.AddModelError("", "Update not succeeded"); } SetViewBag(product.CategoryID); return(View("Index")); }
public JsonResult SaveImages(long id, string images) { JavaScriptSerializer serializer = new JavaScriptSerializer(); var listImages = serializer.Deserialize <List <string> >(images); XElement xElement = new XElement("Images"); foreach (var item in listImages) { var subStringItem = ""; int count = 0; for (int i = 0; i < item.Length; i++) { char[] a = new char[item.Length]; a = item.ToArray(); if (a[i] == '/') { count++; } if (count == 3) { subStringItem = item.Substring(i); break; } } xElement.Add(new XElement("Image", subStringItem)); } var productController = new MoProductController(); try { productController.UpdateMoreImages(id, xElement.ToString()); return(Json(new { status = true })); } catch { return(Json(new { status = false })); } }
public ActionResult AddItem(long productId, int quantity) { var product = new MoProductController().ViewDetail(productId); var cart = Session[CartSession]; if (cart != null) { var list = (List <CartItem>)cart; if (list.Exists(x => x.Product.ID == productId)) { foreach (var item in list) { if (item.Product.ID == productId) { item.Quantity += quantity; } } } else { //Tạo mới đối tượng item var item = new CartItem(); item.Product = product; item.Quantity = quantity; list.Add(item); } Session[CartSession] = list; } else { //Tạo mới đối tượng item var item = new CartItem(); item.Product = product; item.Quantity = quantity; var list = new List <CartItem>(); list.Add(item); //Gán Session[CartSession] = list; } return(RedirectToAction("Index")); }
public ActionResult Search(string keyword, int page = 1) { int totalRecord = 0; int pageSize = 12; var model = new MoProductController().Search(keyword, ref totalRecord, page, pageSize); ViewBag.Total = totalRecord; ViewBag.Page = page; ViewBag.Keyword = keyword; int maxPage = 5; int totalPage = 0; totalPage = (int)Math.Ceiling((double)(totalRecord / pageSize)); ViewBag.TotalPage = totalPage; ViewBag.MaxPage = maxPage; ViewBag.First = 1; ViewBag.Last = totalPage; ViewBag.Next = page + 1; ViewBag.Prev = page - 1; return(View(model)); }
public ActionResult Detail(long Id) { var product = new MoProductController().ViewDetail(Id); return(View(product)); }
public void SetViewBag(long?selectedID = null) { var productController = new MoProductController(); ViewBag.ProductID = new SelectList(productController.ListAll(), "ID", "Name", selectedID); }