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 getLineItem(string variantChoiced, string query)
        {
            try
            {
                LineItemsOfOrder productVariantOfProduct = new LineItemsOfOrder();
                List <Product>   products = new List <Product>();
                if (string.IsNullOrEmpty(query))
                {
                    products = productService.GetAll();
                }
                else
                {
                    string where = string.Format("ProductName like N'%{0}%' or Tags like N'%{1}%' ", query, query);
                    where       += string.Format(" or ProductID in (select Product.ProductID from Product left join TblOption on Product.ProductID = TblOption.ProductID " +
                                                 " where OptionValue like N'%{0}%')", query);
                    products = productService.GetByWhere(where);
                }

                List <int> variantIDs = new List <int>();
                if (!string.IsNullOrEmpty(variantChoiced))
                {
                    variantChoiced = SString.RemoveElementAtBeginEnd(variantChoiced, ",");
                    string[] temp = variantChoiced.Split(',');
                    foreach (var item in temp)
                    {
                        variantIDs.Add(SNumber.ToNumber(item));
                    }
                }

                if (products != null && products.Count > 0)
                {
                    foreach (var item in products)
                    {
                        List <Variant> variants = variantService.GetByProductID(item.ProductID);
                        if (variants != null && variants.Count > 0)
                        {
                            if (variants.Count == 1 && variants[0].Option1 == "Default Title")
                            {
                                LineItem temp = new LineItem();
                                temp.VariantID  = variants[0].VariantID;
                                temp.SKU        = variants[0].VariantSKU;
                                temp.ProductID  = item.ProductID;
                                temp.ObjectName = item.ProductName;
                                temp.IsDefault  = true;
                                temp.Price      = SNumber.ToNumber(variants[0].VariantPrice);
                                temp.Quantity   = 1;

                                var thumb = ImageService.GetPathImageFirstOfProduct(item.ProductID);
                                temp.ImageUrl = thumb;
                                if (!variantIDs.Contains(temp.VariantID))
                                {
                                    temp.CanChoice = true;
                                }
                                else
                                {
                                    temp.CanChoice = false;
                                }
                                productVariantOfProduct.ProductVariants.Add(temp);
                            }
                            else
                            {
                                LineItem product = new LineItem();
                                product.VariantID  = 0;
                                product.ProductID  = item.ProductID;
                                product.ObjectName = item.ProductName;
                                product.IsDefault  = true;
                                product.Price      = -1;
                                product.CanChoice  = false;
                                product.Quantity   = 1;
                                var thumb = ImageService.GetPathImageFirstOfProduct(item.ProductID);
                                product.ImageUrl = thumb;
                                productVariantOfProduct.ProductVariants.Add(product);

                                for (int i = 0; i < variants.Count; i++)
                                {
                                    LineItem temp = new LineItem();
                                    temp.ProductID  = item.ProductID;
                                    temp.VariantID  = variants[i].VariantID;
                                    temp.ObjectName = variants[i].VariantTittle;
                                    temp.SKU        = variants[i].VariantSKU;
                                    temp.IsDefault  = false;
                                    temp.Price      = SNumber.ToNumber(variants[i].VariantPrice);
                                    temp.Quantity   = 1;
                                    if (!variantIDs.Contains(temp.VariantID))
                                    {
                                        temp.CanChoice = true;
                                    }
                                    else
                                    {
                                        temp.CanChoice = false;
                                    }

                                    TblImage image = imageService.GetByPrimaryKey(variants[i].ImageID);
                                    if (image != null)
                                    {
                                        temp.ImageUrl = image.ImageUrl;
                                    }
                                    productVariantOfProduct.ProductVariants.Add(temp);
                                }
                            }
                        }
                    }
                }
                return(View(productVariantOfProduct));
            }
            catch (Exception ex)
            {
                LogService.WriteException(ex);
                return(null);
            }
        }
Beispiel #3
0
 public string UpdateOptionOfProduct(int productID)
 {
     try
     {
         string         result = "";
         List <Variant> variants = new VariantService().GetByProductID(productID);
         string         optionValue1 = "", optionValue2 = "", optionValue3 = "";
         if (variants != null && variants.Count > 0)
         {
             foreach (var item in variants)
             {
                 if (!string.IsNullOrEmpty(item.Option1))
                 {
                     if (!optionValue1.Contains(item.Option1))
                     {
                         optionValue1 += item.Option1 + ",";
                     }
                 }
                 if (!string.IsNullOrEmpty(item.Option2))
                 {
                     if (!optionValue2.Contains(item.Option2))
                     {
                         optionValue2 += item.Option2 + ",";
                     }
                 }
                 if (!string.IsNullOrEmpty(item.Option3))
                 {
                     if (!optionValue3.Contains(item.Option3))
                     {
                         optionValue3 += item.Option3 + ",";
                     }
                 }
             }
             optionValue1 = SString.RemoveElementAtBeginEnd(optionValue1, ",");
             optionValue2 = SString.RemoveElementAtBeginEnd(optionValue2, ",");
             optionValue3 = SString.RemoveElementAtBeginEnd(optionValue3, ",");
         }
         List <TblOption> options = GetByProductID(productID);
         if (options != null && options.Count > 0)
         {
             for (int i = 0; i < options.Count; i++)
             {
                 if (i == 0)
                 {
                     options[i].OptionValue = optionValue1;
                 }
                 else if (i == 1)
                 {
                     options[i].OptionValue = optionValue2;
                 }
                 else if (i == 2)
                 {
                     options[i].OptionValue = optionValue3;
                 }
                 Update(options[i]);
             }
         }
         return(result);
     }
     catch (Exception ex)
     {
         LogService.WriteException(ex);
         return("");
     }
 }