Exemplo 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);
        }
Exemplo n.º 2
0
        public void CheckIfPriceIsChanged(int channelId, string productName, string productUrl, decimal price)
        {
            CanonDataContext db = Cdb.Instance;
            //try to find mapping rule
            MappingRule mr = db.MappingRules.Where(m => m.ChannelId == channelId &&
                                                   m.MonitoredName == productName &&
                                                   m.MonitoredUrl == productUrl).FirstOrDefault();

            if (mr == null)
            {
                return;
            }

            decimal?currentPrice = CanonMapping.GetCurrentMapPrice(channelId, productName, productUrl);

            if (currentPrice == null)
            {
                return;
            }

            if ((decimal)currentPrice == price)
            {
                CanonProductsLog.Add(channelId, mr.ProductId, MappingLogEnum.PriceWithoutChanges);
            }
            else
            {
                CanonProductsLog.Add(channelId, mr.ProductId, MappingLogEnum.NewPrice, price.ToString());
            }
        }
Exemplo n.º 3
0
        public static void AddToExceptions(int channelId, int productId)
        {
            CanonDataContext db   = Cdb.Instance;
            MappingRule      rule = db.MappingRules.Where(r => r.ChannelId == channelId &&
                                                          r.ProductId == productId).FirstOrDefault();

            if (rule != null)
            {
                db.MappingRules.DeleteOnSubmit(rule);
            }

            Excluded old = db.Excludeds.FirstOrDefault(d => d.ChannelId == channelId && d.ProductId == productId);

            if (old != null)
            {
                return;
            }
            Excluded exc = new Excluded();

            exc.ProductId = productId;
            exc.ChannelId = channelId;
            db.Excludeds.InsertOnSubmit(exc);
            db.SubmitChanges();
            CanonProductsLog.Add(channelId, productId, MappingLogEnum.AddedToExceptions);
        }
Exemplo n.º 4
0
        public static void RemoveFromExceptions(int channelId, int productId)
        {
            CanonDataContext db   = Cdb.Instance;
            Excluded         prod = db.Excludeds.Where(r => r.ChannelId == channelId &&
                                                       r.ProductId == productId).FirstOrDefault();

            if (prod != null)
            {
                db.Excludeds.DeleteOnSubmit(prod);
            }

            db.SubmitChanges();

            CanonProductsLog.Add(channelId, productId, MappingLogEnum.RemovedFromExceptions);
        }
Exemplo n.º 5
0
        public Product InsertUpdateProduct()
        {
            CanonDataContext db     = Cdb.Instance;
            int?   categoryId       = this.InsertUpdateCategory();
            bool   isProductCreated = false;
            bool   isNameChanged    = false;
            string oldName          = string.Empty;
            //find product
            Product existing = db.Products.FirstOrDefault(p => p.ProductCode == this.ProductCode);

            if (existing == null)
            {
                existing = new Product();
                db.Products.InsertOnSubmit(existing);
                isProductCreated = true;
            }
            else
            {
                if (existing.ProductName != this.ProductName)
                {
                    oldName       = existing.ProductName;
                    isNameChanged = true;
                }
            }
            existing.ProductCode  = this.ProductCode;
            existing.ProductName  = this.ProductName;
            existing.CurrentPrice = this.CurrentPrice;
            existing.CategoryId   = categoryId;
            existing.IsActive     = this.IsActive;
            db.SubmitChanges();

            //add records into log
            //add log entry that product is created
            if (isProductCreated)
            {
                CanonProductsLog.Add(ProductsLogEnum.ProductIsCreated, existing.ProductId, null, WebVariables.LoggedUserId);
            }
            else if (isNameChanged)
            {
                CanonProductsLog.Add(ProductsLogEnum.NameIsChanged, existing.ProductId, oldName, WebVariables.LoggedUserId);
            }

            return(existing);
        }
Exemplo n.º 6
0
        public static void DeleteMapping(int channelId, int productId)
        {
            CanonDataContext db = Cdb.Instance;

            try
            {
                MappingRule rule = db.MappingRules.Where(r => r.ChannelId == channelId &&
                                                         r.ProductId == productId).FirstOrDefault();
                if (rule != null)
                {
                    db.MappingRules.DeleteOnSubmit(rule);
                    db.SubmitChanges();
                    CanonProductsLog.Add(channelId, productId, MappingLogEnum.DeletedMappingRule);
                }
            }
            catch (Exception)
            {
            }
        }
Exemplo n.º 7
0
        public static void AddRecommendedMapping(int channelId, int productId)
        {
            CanonDataContext db = Cdb.Instance;

            try
            {
                CurrentRelevance cr = db.CurrentRelevances.Where(c => c.BestForMapping == true &&
                                                                 c.ChannelId == channelId &&
                                                                 c.ProductId == productId).FirstOrDefault();
                if (cr != null)
                {
                    MappingRule rule = db.MappingRules.Where(r => r.ChannelId == channelId &&
                                                             r.ProductId == productId).FirstOrDefault();
                    if (rule == null)
                    {
                        //NEW rule
                        MappingRule mr = new MappingRule();
                        mr.ChannelId     = channelId;
                        mr.ProductId     = productId;
                        mr.MonitoredName = cr.ProductName;
                        mr.MonitoredUrl  = cr.ProductUrl;
                        db.MappingRules.InsertOnSubmit(mr);
                        CanonProductsLog.Add(channelId, productId, MappingLogEnum.NewMappingRule);
                    }
                    else
                    {
                        //UPDATED rule
                        rule.MonitoredName = cr.ProductName;
                        rule.MonitoredUrl  = cr.ProductUrl;
                        CanonProductsLog.Add(channelId, productId, MappingLogEnum.ChangedMappingRule);
                    }
                    db.SubmitChanges();
                }
            }
            catch (Exception)
            {
            }
        }