public ActionResult Index() { var viewModel = new CartListViewModel(); var list = GetShoppingCart(); //viewModel.Products = GetSopiingCart(); var pricmodel = _productSevice.GetAttribute("Price"); var Guaranteemodel = _productSevice.GetAttribute("Guarantee"); viewModel.Count = list.Count; viewModel.Products = new List <CartItemViewModel>(); foreach (DictionaryEntry it in list) { CartItemViewModel item = (CartItemViewModel)it.Value; var pr = _productSevice.Get(item.Id); if (pr != null) { viewModel.Products.Add(item); item.Image = pr.Image; item.link = AppHelpers.ProductUrls(pr.Category_Id, pr.Slug); var Guarante = _productSevice.GetAttributeValue(item.Id, Guaranteemodel.Id); if (Guarante != null) { item.Guarantee = Guarante.Value; } var price = _productSevice.GetAttributeValue(item.Id, pricmodel.Id); if (price != null) { try { int p = int.Parse(price.Value); item.Priceint = p; item.Price = p.ToString("N0").Replace(",", ".") + " VND"; viewModel.TotalMoney += p * item.Count; } catch { item.Price = "Liên hệ"; } } else { item.Price = "Liên hệ"; } } } return(View(viewModel)); }
public ActionResult AjaxGetSearch(string search) { var lst = _productSevice.GetFinder().SeachText(search).ToPage(); List <ProductAjaxItem> rlst = new List <ProductAjaxItem>(); if (lst != null) { var pricmodel = _productSevice.GetAttribute("Price"); foreach (var it in lst) { var val = AppHelpers.ProductValues(it); rlst.Add(new ProductAjaxItem { productName = it.Name, productUrl = AppHelpers.ProductUrls(it.Category_Id, it.Slug), productImage = new ProductAjaxImageItem { fullimg = it.Image, medium = AppHelpers.ImageCropUrl(it.Image, 160), }, price = _productSevice.GetAttributeValue(it.Id, pricmodel.Id).Value, }); } } return(Json(rlst, JsonRequestBehavior.AllowGet)); }
public ActionResult Create(AdminEditProductClassViewModel model) { if (ModelState.IsValid) { using (var unitOfWork = UnitOfWorkManager.NewUnitOfWork()) { try { var productClass = new ProductClass { Name = model.Name, Image = model.Image, Description = model.Description, Colour = model.Colour, IsLocked = model.IsLocked }; _productSevice.Add(productClass); if (model.AllAttribute != null) { foreach (var it in model.AllAttribute) { if (it.IsCheck) { var a = new ProductClassAttribute { ProductAttributeId = it.Id, ProductClassId = productClass.Id, IsShow = it.IsShow, }; _productSevice.Add(a); } } } unitOfWork.Commit(); TempData[AppConstants.MessageViewBagName] = new GenericMessageViewModel { Message = "Thành công thêm nhóm sản phẩm", MessageType = GenericMessages.success }; return(RedirectToAction("Index")); } catch { unitOfWork.Rollback(); ModelState.AddModelError("", "Lỗi khi thêm nhóm sản phẩm"); } } } foreach (var it in model.AllAttribute) { it.Name = _productSevice.GetAttribute(it.Id).LangName; } return(View(model)); }