Ejemplo n.º 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);
        }
Ejemplo n.º 2
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();
            }
        }