public ActionResult detail(int id) { try { Product product = productService.GetByPrimaryKey(id); if (product != null) { product.Variants = variantService.GetByProductID(product.ProductID); product.Images = imageService.GetByProductID(product.ProductID); product.Options = optionService.GetByProductID(product.ProductID); if (product.Options != null && product.Options.Count > 0) { foreach (var item in product.Options) { if (!string.IsNullOrEmpty(item.OptionValue)) { if (item.OptionName != "Title" && item.OptionValue != "DefaultTitle") { item.OptionValues = (SString.RemoveElementAtBeginEnd(item.OptionValue, ",")).Split(',').ToList <string>(); } } } } if (!string.IsNullOrEmpty(product.Tags)) { List <string> listTag = (SString.RemoveElementAtBeginEnd(product.Tags, ",")).Split(',').ToList <string>(); foreach (var item in listTag) { product.ListTag.Add(new Tag { TagName = item }); } } string where = string.Format("SupplierID={0} and ProductStyleID={1} and ProductID <>{2}", product.SupplierID, product.ProductStyleID, product.ProductID); product.ProductsRelation = productService.GetByWhere(where); if (product.ProductsRelation != null && product.ProductsRelation.Count > 0) { foreach (var item in product.ProductsRelation) { item.Variants = variantService.GetByProductID(item.ProductID); item.Images = imageService.GetByProductID(item.ProductID); } } return(View(product)); } return(RedirectToAction("grid")); } catch (Exception ex) { LogService.WriteException(ex); throw; } }
public ActionResult create(int productID) { try { Variant variant = new Variant(); variant.ProductID = productID; variant.Product = productService.GetByPrimaryKey(productID); variant.Product.Variants = variantService.GetByProductID(productID); if (variant.Product.Variants != null && variant.Product.Variants.Count > 0) { foreach (var item in variant.Product.Variants) { item.Image = imageService.GetByPrimaryKey(item.ImageID); } } variant.Product.Options = optionService.GetByProductID(productID); variant.Product.Images = imageService.GetByProductID(productID); variant.WeightUnit = "kg"; return(View(variant)); } catch (Exception ex) { LogService.WriteException(ex); } return(RedirectToAction("detail", "products", new { id = productID })); }
public ActionResult detail(int id, string strMessage = "", string messageUpload = "", string messageDelete = "") { try { string strError = "", strSuccess = ""; if (!string.IsNullOrEmpty(strMessage)) { if (strMessage.Equals("1")) { strSuccess = Common.UpdateSuccess + "</br>"; } else if (strMessage.Equals("0")) { strError = Common.UpdateFail + "</br>"; } else if (strMessage.Equals("Variant1")) { strSuccess = "Xoá phiên bản thành công" + "</br>"; } else if (strMessage.Equals("Variant0")) { strError = "Xoá phiên bản thất bại" + "</br>"; } else if (strMessage.Equals("delete0")) { strError = "Xoá sản phẩm thất bại" + "</br>"; } } if (messageUpload == "0") { strError += "Upload ảnh không thành công</br>"; } else if (messageUpload == "1") { strSuccess += "Upload ảnh thành công</br>"; } else if (messageUpload == "2") { strError += "Kích thước file > 1MB</br>"; } if (messageDelete == "0") { strError += "Xóa ảnh không thành công</br>"; } else if (messageDelete == "1") { strSuccess += "Xóa ảnh thành công</br>"; } ViewBag.strSuccess = strSuccess; ViewBag.strError = strError; Product product = productService.GetByPrimaryKey(id); if (product != null) { List <ProductStyle> productStyle = productStyleService.GetAll(); productStyle.Insert(0, new ProductStyle { ProductStyleID = 0, ProductStyleName = "Chọn loại sản phẩm" }); product.ProductStyles = new SelectList(productStyle, "ProductStyleID", "ProductStyleName", product.ProductStyleID.ToString()); List <Supplier> supplier = supplierService.GetAll(); supplier.Insert(0, new Supplier { SupplierID = 0, SupplierName = "Chọn nhà sản xuất" }); product.Suppliers = new SelectList(supplier, "SupplierID", "SupplierName", product.SupplierID.ToString()); List <TblImage> images = imageService.GetByProductID(id); product.Images = images; product.CollectionProducts = collectionProductService.GetByProductID(id); product.Options = optionService.GetByProductID(id); product.ListTag = tagService.GetByTableNameID((int)Common.TableName.Product); product.Variants = variantService.GetByProductID(id); product.Variant = null; if (product.Variants != null && product.Variants.Count > 0) { foreach (var item in product.Variants) { item.Image = imageService.GetByPrimaryKey(item.ImageID); } product.Variant = product.Variants[0]; } return(View(product)); } } catch (Exception ex) { LogService.WriteException(ex); } return(RedirectToAction("", "products", new { strMessage = "notExist" })); }