public ActionResult Attribute(string tkn) { var product = _productBusiness.GetListWT(c => c.TokenKey == tkn).FirstOrDefault(); int productId = product.ProductID; var attributeList = _productAttributeBusiness.GetListWT(c => c.ProductId == productId); Mapper.CreateMap <Product, ProductViewModel>(); var vmProduct = Mapper.Map <Product, ProductViewModel>(product); vmProduct.ProductAttributeList = (from il in attributeList where (il.ProductId == product.ProductID) select new ProductAttributeViewModel { Id = il.Id, ProductId = product.ProductID, Attributes = il.Attributes, Price = il.Price }).ToList(); return(PartialView("_Attribute", vmProduct)); }
// // GET: /ProductDetail/ public ActionResult Index(int productId) { var product = _productBusiness.GetListWT(c => c.ProductID == productId).FirstOrDefault(); var imgList = _ImageBusiness.GetListWT(c => c.ProductId == productId); Mapper.CreateMap <Product, ProductViewModel>(); var vmProduct = Mapper.Map <Product, ProductViewModel>(product); CookieStore mycookie = new CookieStore(); var assignedProductList = new List <AddToCart>(); var products = mycookie.GetCookie(Enumerator.CustomerAction.AddToCart.ToString()); if (!string.IsNullOrEmpty(products)) { assignedProductList = (from p in products.Split(',') select new AddToCart { ProductId = Convert.ToInt32(p.Split('~')[0]), Quantity = Convert.ToInt32(p.Split('~')[1]), Size = Convert.ToInt32(p.Split('~')[2]), Attributes = p.Split('~')[3] }).ToList(); } var productAssigned = assignedProductList.Where(c => c.ProductId == productId).FirstOrDefault(); if (productAssigned != null) { vmProduct.SizeId = productAssigned.Size.Value; vmProduct.Attributes = productAssigned.Attributes; vmProduct.Price = _productBusiness.GetSelectedPrice(productId, productAssigned.Size.Value, productAssigned.Attributes) * productAssigned.Quantity; vmProduct.ProductQuantity = productAssigned.Quantity; } else { var defaultSize = _productSizeBusiness.GetListWT(c => c.ProductId == productId).FirstOrDefault(); vmProduct.SizeId = defaultSize == null ? 0 : defaultSize.Id; vmProduct.Attributes = ""; vmProduct.Price = _productBusiness.GetDefaultPrice(productId); vmProduct.ProductQuantity = 1; } vmProduct.DiscountPercent = vmProduct.DiscountPercent ?? 0; vmProduct.DiscountedPrice = Math.Round(vmProduct.Price - Decimal.Divide(vmProduct.DiscountPercent ?? 0, 100) * vmProduct.Price); vmProduct.ImageList = (from il in imgList where (il.ProductId == product.ProductID) select new ImageViewModel { ProductId = product.ProductID, Images = "/ProductImage/" + il.Images }).ToList(); vmProduct.ProductSizeList = (from ps in _productSizeBusiness.GetListWT(c => c.ProductId == productId).ToList() select new ProductSizeViewModel { Id = ps.Id, ProductId = ps.ProductId, Price = ps.Price, Size = ps.Size }).ToList(); vmProduct.ProductAttributeList = (from ps in _productAttributeBusiness.GetListWT(c => c.ProductId == productId).ToList() select new ProductAttributeViewModel { Id = ps.Id, ProductId = ps.ProductId, Price = ps.Price, Attributes = ps.Attributes }).ToList(); var breadcrumb = new List <KeyValuePair <string, string> >(); breadcrumb.Add(new KeyValuePair <string, string>("Home", "/Home/index")); var category = _CategoryBusiness.GetListWT(c => c.CategoryId == vmProduct.CategoryId).FirstOrDefault(); if (category != null) { breadcrumb.Add(new KeyValuePair <string, string>(category.CategoryName, "/Product/index?categoryid=" + category.CategoryId)); } var subcategory = _SubCategoryBusiness.GetListWT(c => c.SubCategoryId == vmProduct.SubCategoryId).FirstOrDefault(); if (subcategory != null) { breadcrumb.Add(new KeyValuePair <string, string>(subcategory.SubCategoryName, "/Product/index?subcategoryid=" + subcategory.SubCategoryId)); } breadcrumb.Add(new KeyValuePair <string, string>(vmProduct.ProductName, "")); ViewBag.BreadCrumb = breadcrumb.ToList(); return(View(vmProduct)); }