示例#1
0
        public RecommendedPrice InsertUpdatePrice(Product updated)
        {
            CanonDataContext db          = Cdb.Instance;
            RecommendedPrice imported    = this.RecommendedPrices[0];
            RecommendedPrice recommended = db.RecommendedPrices.FirstOrDefault(u => u.ProductId == updated.ProductId &&
                                                                               u.ChangeDate.Date == DateTime.Now.Date);

            if (recommended == null)
            {
                recommended = new RecommendedPrice();
                db.RecommendedPrices.InsertOnSubmit(recommended);
            }
            recommended.Price      = imported.Price;
            recommended.ProductId  = updated.ProductId;
            recommended.ChangeDate = DateTime.Now;
            recommended.UserId     = WebVariables.LoggedUserId;
            if (IsLastRecommendedPriceDifferent(recommended))
            {
                //add into log that price is changed
                CanonProductsLog.Add(ProductsLogEnum.PriceIsChanged, recommended.ProductId,
                                     recommended.Price.ToString(), WebVariables.LoggedUserId);
                CanonProductsLog.AddRecommendedLog(WebVariables.LoggedUserId,
                                                   updated.ProductId,
                                                   RecommendedChangeSourceEnum.Import,
                                                   recommended.Price, recommended.ChangeDate);
            }
            db.SubmitChanges();
            return(recommended);
        }
示例#2
0
        public bool IsLastRecommendedPriceDifferent(RecommendedPrice newPrice)
        {
            RecommendedPrice prod = Cdb.Instance.RecommendedPrices.OrderByDescending(u => u.ChangeDate).FirstOrDefault(u => u.ProductId == newPrice.ProductId);

            if (prod == null)
            {
                return(true);
            }
            if (prod.Price != newPrice.Price)
            {
                return(true);
            }
            return(false);
        }
示例#3
0
        public static void UpdateRecommendedPrice(int recordId, decimal newPrice)
        {
            CanonDataContext db   = Cdb.Instance;
            RecommendedPrice prod = db.RecommendedPrices.FirstOrDefault(u => u.PriceId == recordId);

            if (prod != null)
            {
                RecommendedPrice last = db.RecommendedPrices.OrderByDescending(p => p.ChangeDate).FirstOrDefault(u => u.ProductId == prod.ProductId);
                prod.Price = newPrice;
                CanonProductsLog.AddRecommendedLog(WebVariables.LoggedUserId, prod.ProductId,
                                                   RecommendedChangeSourceEnum.Manual,
                                                   newPrice, prod.ChangeDate);
                //update current price in products table
                if (prod.PriceId == last.PriceId)
                {
                    Product product = db.Products.Where(p => p.ProductId == prod.ProductId).FirstOrDefault();
                    product.CurrentPrice = newPrice;
                }
                db.SubmitChanges();
            }
        }
示例#4
0
        /// <summary>
        /// Parses a row
        /// </summary>
        /// <param name="row"></param>
        /// <returns></returns>
        public T ParseRow(Object row)
        {
            if (!(row is DataRow))
            {
                throw new ArgumentException("Only DataRow object can be passed.");
            }

            DataRow dr = row as DataRow;

            //get, validate EAN code
            if (dr[0] == null)
            {
                return(null);
            }
            string ean = dr[0].ToString();

            if ((string.IsNullOrEmpty(ean)) || (ean.Length < 10) || (ean.Length > 13))
            {
                return(null);
            }
            //get, validate product name
            if (dr[1] == null)
            {
                return(null);
            }
            string name = dr[1].ToString();

            if (string.IsNullOrEmpty(name))
            {
                return(null);
            }
            //get, validate recommended price
            if (dr[5] == null)
            {
                return(null);
            }
            string price = dr[5].ToString();
            //synonims, stopwords
            string synonims  = string.Empty;
            string stopwords = string.Empty;

            if (dr[13] != null)
            {
                synonims = dr[13].ToString();
            }
            if (dr[14] != null)
            {
                stopwords = dr[14].ToString();
            }
            //category
            string category = string.Empty;

            if (dr[12] != null)
            {
                category = dr[12].ToString();
            }
            double dPrice = 0;

            if (!string.IsNullOrEmpty(price))
            {
                try
                {
                    dPrice = double.Parse(price, culture.NumberFormat);
                }
                catch (Exception ex)
                {
                    ErrorMessages.Add(new ImportErrorMessage("CantParseNumber", new string[] { price.ToString() }));
                    WebVariables.Logger.Error(string.Format("File {0}, error number parse {1}", _filename, price), ex);
                    return(null);
                }
            }
            //create new product
            CanonDataContext db = Cdb.Instance;
            T a = Activator.CreateInstance <T>();

            a.ProductCode  = ean;
            a.ProductName  = name;
            a.IsActive     = true;
            a.CurrentPrice = (decimal)dPrice;

            if (dPrice > 0)
            {
                RecommendedPrice newPrice = new RecommendedPrice();
                newPrice.ChangeDate = DateTime.Now;
                newPrice.UserId     = WebVariables.LoggedUserId;
                newPrice.Price      = (decimal)dPrice;
                newPrice.Product    = a;
                a.RecommendedPrices.Add(newPrice);
            }
            if (!string.IsNullOrEmpty(category))
            {
                Category newCat = new Category();
                newCat.CategoryName = category;
                newCat.InternalId   = category;
                a.Category          = newCat;
            }

            //update product relevance words
            string filteredName = name.Replace(",", "").Replace(";", "");

            string[]          nameTokens = filteredName.Split(' ');
            string[]          synTokens  = synonims.Split(' ');
            int               maxValue   = this.CountMaxRelevance(2, nameTokens, synTokens);
            ProductsRelevance fromCode   = new ProductsRelevance();

            fromCode.Word   = ean;
            fromCode.Points = 2;
            fromCode.Max    = maxValue;
            a.ProductsRelevances.Add(fromCode);

            //update relevance from name
            foreach (string nameToken in nameTokens)
            {
                if (nameToken.Trim().Length < 2)
                {
                    continue;
                }
                ProductsRelevance fromName = new ProductsRelevance();
                fromName.Word   = nameToken;
                fromName.Points = 2;
                fromName.Max    = maxValue;
                a.ProductsRelevances.Add(fromName);
            }

            //update relevance from synonims
            foreach (string synToken in synTokens)
            {
                if (synToken.Trim().Length < 2)
                {
                    continue;
                }
                ProductsRelevance fromSyn = new ProductsRelevance();
                fromSyn.Word   = synToken;
                fromSyn.Points = 1;
                fromSyn.Max    = maxValue;
                a.ProductsRelevances.Add(fromSyn);
            }

            //update relevance from stopwords
            string[] stopTokens = stopwords.Split(' ');
            foreach (string stopToken in stopTokens)
            {
                if (stopToken.Trim().Length < 2)
                {
                    continue;
                }
                ProductsRelevance fromStop = new ProductsRelevance();
                fromStop.Word   = stopToken;
                fromStop.Points = -1;
                fromStop.Max    = maxValue;
                a.ProductsRelevances.Add(fromStop);
            }

            return(a);
        }
示例#5
0
 public bool IsLastRecommendedPriceDifferent(RecommendedPrice newPrice)
 {
     RecommendedPrice prod = Cdb.Instance.RecommendedPrices.OrderByDescending(u => u.ChangeDate).FirstOrDefault(u => u.ProductId == newPrice.ProductId);
     if (prod == null)
         return true;
     if (prod.Price != newPrice.Price)
         return true;
     return false;
 }
示例#6
0
        public RecommendedPrice InsertUpdatePrice(Product updated)
        {
            CanonDataContext db = Cdb.Instance;
            RecommendedPrice imported = this.RecommendedPrices[0];
            RecommendedPrice recommended = db.RecommendedPrices.FirstOrDefault(u => u.ProductId == updated.ProductId
                                                                && u.ChangeDate.Date == DateTime.Now.Date);

            if (recommended == null)
            {
                recommended = new RecommendedPrice();
                db.RecommendedPrices.InsertOnSubmit(recommended);
            }
            recommended.Price = imported.Price;
            recommended.ProductId = updated.ProductId;
            recommended.ChangeDate = DateTime.Now;
            recommended.UserId = WebVariables.LoggedUserId;
            if (IsLastRecommendedPriceDifferent(recommended))
            {
                //add into log that price is changed
                CanonProductsLog.Add(ProductsLogEnum.PriceIsChanged, recommended.ProductId,
                                     recommended.Price.ToString(), WebVariables.LoggedUserId);
                CanonProductsLog.AddRecommendedLog(WebVariables.LoggedUserId,
                                                   updated.ProductId,
                                                   RecommendedChangeSourceEnum.Import,
                                                   recommended.Price, recommended.ChangeDate);
            }
            db.SubmitChanges();
            return recommended;
        }