Beispiel #1
0
        public JsonResult Update(int keywordID, string products)
        {
            var jsonSuccessResult = new JsonSuccessResult();

            try
            {
                string[] arrProducts = products.Split(',');

                var curList = ProductKeywords.GetByKeywordID(keywordID);

                foreach (var product in arrProducts)
                {
                    int productID = Int32.Parse(product);

                    if (!curList.Any(item => item.ProductID == productID &&
                                     item.KeywordID == keywordID))
                    {
                        var kp = new ProductKeyword
                        {
                            ProductID  = productID,
                            KeywordID  = keywordID,
                            LastUpdate = DateTime.Now
                        };

                        ProductKeywords.Insert(kp);
                    }
                    else
                    {
                        curList.Remove(curList.Single(cls => cls.KeywordID == keywordID &&
                                                      cls.ProductID == productID));
                    }
                }

                foreach (var item in curList)
                {
                    ProductKeywords.Delete(item.ID);
                }

                jsonSuccessResult.Success = true;
            }
            catch (Exception ex)
            {
                jsonSuccessResult.Errors  = new string[] { ex.Message };
                jsonSuccessResult.Success = false;
            }

            return(new JsonResult()
            {
                Data = jsonSuccessResult
            });
        }
Beispiel #2
0
        private static void SaveDefaultKeywords(string[] keywords, int productID)
        {
            List <ProductKeyword> keys = new List <ProductKeyword>();

            foreach (var key in keywords)
            {
                if (key != null && key != String.Empty)
                {
                    var orgKey = Keywords.GetByTitle(key);

                    if (orgKey != null)
                    {
                        if (orgKey.IsActive)
                        {
                            var pk = new ProductKeyword
                            {
                                KeywordID  = orgKey.ID,
                                ProductID  = productID,
                                LastUpdate = DateTime.Now
                            };

                            keys.Add(pk);
                        }
                    }
                    else
                    {
                        int keyID = InsertKeyword(key);

                        var pk = new ProductKeyword
                        {
                            KeywordID  = keyID,
                            ProductID  = productID,
                            LastUpdate = DateTime.Now
                        };

                        keys.Add(pk);
                    }
                }
            }

            if (keys.Count > 0)
            {
                ProductKeywords.Insert(keys);
            }
        }
Beispiel #3
0
        private static void SaveKeywords(EditProduct editProduct, int productID)
        {
            var curList = ProductKeywords.GetByProductID(productID);

            foreach (var key in editProduct.Keywords)
            {
                if (key.KeywordID == -1)
                {
                    key.KeywordID = InsertKeyword(key.Title);
                }

                if (!curList.Any(item => item.ID == key.ID))
                {
                    var rpt = IsRepeatKey(key.KeywordID, productID);

                    if (!rpt)
                    {
                        var productKeyword = Mapper.Map <ProductKeyword>(key);

                        productKeyword.ProductID = productID;

                        ProductKeywords.Insert(productKeyword);
                    }
                }
                else
                {
                    ProductKeywords.Update(key);
                    curList.Remove(curList.Single(cls => cls.ID == key.ID));
                }
            }

            foreach (var item in curList)
            {
                ProductKeywords.Delete(item.ID);
            }
        }