public ActionResult UpdateProductCompareSource(int ProductID, int ProductCompareSourceID, int?BrandID, int?ProductGroupID, int?EditableRank)
        {
            using (var unit = GetUnitOfWork())
            {
                var contentPrice = unit.Service <ContentPrice>().GetAll(c => c.ProductID == ProductID && c.ConnectorID == Client.User.ConnectorID).FirstOrDefault();
                int vendorID     = unit.Service <Content>().Get(x => x.ProductID == ProductID && x.ConnectorID == Client.User.ConnectorID.Value).ContentProduct.VendorID;

                if (contentPrice == null)
                {
                    contentPrice = new ContentPrice();
                    contentPrice.ContentPriceRuleIndex = 0;
                    contentPrice.ProductID             = ProductID;
                    contentPrice.Margin      = "%";
                    contentPrice.VendorID    = vendorID;
                    contentPrice.ConnectorID = Client.User.ConnectorID.Value;
                    unit.Service <ContentPrice>().Create(contentPrice);
                }

                contentPrice.BrandID        = null;
                contentPrice.ProductGroupID = null;
                //contentPrice.ProductGroupID = (ProductGroupID.HasValue) ? ProductGroupID : contentPrice.ProductGroupID;
                contentPrice.ComparePricePosition = EditableRank;
                contentPrice.PriceRuleType        = 1;
                contentPrice.CompareSourceID      = ProductCompareSourceID;

                unit.Save();
            }

            return(Json(new
            {
                success = true
            }));
        }
        public ActionResult Update(int id, decimal?NewPrice, decimal?NewMarge, int?CurrentRank, string PriceLabel)
        {
            using (var unit = GetUnitOfWork())
            {
                var RelevantContentPrice = unit.Service <ContentPrice>().Get(c => c.ProductID == id);

                int vendorID = unit.Service <Content>().Get(x => x.ProductID == id && x.ConnectorID == Client.User.ConnectorID.Value).ContentProduct.VendorID;

                if (RelevantContentPrice == null)
                {
                    RelevantContentPrice = new ContentPrice();
                    //newContentPrice.CompareSourceID = ProductCompareSourceID;
                    RelevantContentPrice.ContentPriceRuleIndex = 0;
                    RelevantContentPrice.ProductID             = id;
                    RelevantContentPrice.Margin        = "%";
                    RelevantContentPrice.VendorID      = vendorID;
                    RelevantContentPrice.ConnectorID   = Client.User.ConnectorID.Value;
                    RelevantContentPrice.PriceRuleType = 1;
                    unit.Service <ContentPrice>().Create(RelevantContentPrice);
                }

                RelevantContentPrice.BrandID              = null;
                RelevantContentPrice.ProductGroupID       = null;
                RelevantContentPrice.FixedPrice           = (NewPrice.HasValue) ? NewPrice : RelevantContentPrice.FixedPrice;
                RelevantContentPrice.UnitPriceIncrease    = (NewMarge.HasValue) ? NewMarge : RelevantContentPrice.UnitPriceIncrease;
                RelevantContentPrice.ComparePricePosition = (CurrentRank.HasValue) ? CurrentRank : RelevantContentPrice.ComparePricePosition;
                RelevantContentPrice.ContentPriceLabel    = (!String.IsNullOrEmpty(PriceLabel)) ? PriceLabel : RelevantContentPrice.ContentPriceLabel;

                unit.Save();
            }
            return(Json(new
            {
                success = true
            }));
        }
Esempio n. 3
0
 public void ApplySaleLogic(Article article, ContentPrice priceRule)
 {
     if (priceRule.FromDate != null || priceRule.ToDate != null) //If the UnitPriceIncrease is a number below 1.0 the priceRule is a discount. If it is, the ProFrom and ProTo need to be filled, and the CountryCode needs to be filled with "SLD".
     {
         article.ProFrom     = priceRule.FromDate.ToNullOrLocal().ParseToFormatOrReturnEmptyString(Constants.SaleDateFormat);
         article.ProTo       = priceRule.ToDate.ToNullOrLocal().ParseToFormatOrReturnEmptyString(Constants.SaleDateFormat);
         article.CountryCode = Constants.SaleTarrif;
     }
 }
Esempio n. 4
0
        public void ApplySaleLogic_DoesNotChange_ProFrom_And_ProTo_Dates_When_Supplied_ContentPrice_Without_ProFrom_Or_ProTo_Dates()
        {
            var newArticle   = new Article();
            var newPriceRule = new ContentPrice
            {
                UnitPriceIncrease = 0.8M
            };

            newArticle.ApplySaleLogic(newArticle, newPriceRule);

            Assert.IsTrue(
                String.IsNullOrEmpty(newArticle.ProFrom) &&
                String.IsNullOrEmpty(newArticle.ProTo) &&
                newArticle.CountryCode != Constants.SaleTarrif
                );
        }
Esempio n. 5
0
        public void ApplySaleLogic_Changes_ProFrom_And_ProTo_Dates_And_CountryCode_When_Supplied_ContentPrice()
        {
            var newArticle = new Article();
            var fromDate   = DateTime.Now;
            var toDate     = DateTime.Now.AddDays(7);

            var newPriceRule = new ContentPrice
            {
                UnitPriceIncrease = 0.8M,
                FromDate          = fromDate,
                ToDate            = toDate
            };

            newArticle.ApplySaleLogic(newArticle, newPriceRule);

            Assert.IsTrue(
                newArticle.ProFrom == fromDate.ToString(Constants.SaleDateFormat) &&
                newArticle.ProTo == toDate.ToString(Constants.SaleDateFormat) &&
                newArticle.CountryCode == Constants.SaleTarrif
                );
        }
Esempio n. 6
0
        private Boolean CheckPriceRuleForArticle(Article article, ContentPrice priceRule)
        {
            var result = priceRule.VendorID == article.VendorID;

            if (result && priceRule.ProductID.HasValue && priceRule.ProductID != article.ArticleID && priceRule.ProductID != article.ProductID)
            {
                result = false;
            }

            if (result && priceRule.BrandID.HasValue && priceRule.BrandID != article.BrandID)
            {
                result = false;
            }

            if (result && priceRule.AttributeID.HasValue && !priceRule.AttributeValue.IsNullOrWhiteSpace())
            {
                var attributeValues = Database
                                      .Query <ProductAttributeValue>(GetAttributeValue, priceRule.AttributeID.Value, article.ArticleID, article.ProductID)
                                      .Where(attributeValue => !attributeValue.LanguageID.HasValue)
                                      .ToDictionary(attributeValue => attributeValue.ProductID, attributeValue => attributeValue.Value);

                // First check the value on the lowest product level (SKU), then go upwards in the hierarchy (Color or Style)
                if (attributeValues.GetValueOrDefault(article.ProductID) != priceRule.AttributeValue && attributeValues.GetValueOrDefault(article.ArticleID) != priceRule.AttributeValue)
                {
                    result = false;
                }
            }

            if (result &&
                priceRule.ProductGroupID.HasValue &&
                priceRule.ProductGroupID != article.CategoryID &&
                priceRule.ProductGroupID != article.FamilyID &&
                priceRule.ProductGroupID != article.SubfamilyID)
            {
                result = false;
            }

            return(result);
        }
        private void importExcelToDb(string fullName)
        {
            using (var unit = GetUnitOfWork())
            {
                //var currentConnectorID = Client.User.ConnectorID;
                //var currentConnectorID = 1;
                if (System.IO.File.Exists(fullName))
                {
                    FileStream       excelStream = System.IO.File.Open(fullName, FileMode.Open, FileAccess.Read);
                    IExcelDataReader excelReader = null;
                    excelReader = ExcelReaderFactory.CreateOpenXmlReader(excelStream);

                    var ds      = excelReader.AsDataSet();
                    var temp    = (from p in ds.Tables[0].AsEnumerable().Skip(2) select p).FirstOrDefault();
                    var content = (from p in ds.Tables[0].AsEnumerable().Skip(2)
                                   let numberOfFields = p.ItemArray.Count()
                                                        select new
                    {
                        connectorID = Convert.ToInt32(p.Field <object>(numberOfFields - 1)),
                        vendorID = Convert.ToInt32(p.Field <object>(numberOfFields - 2)),
                        productID = Convert.ToInt32(p.Field <object>(numberOfFields - 3)),
                        Label = Convert.ToString(p.Field <object>(numberOfFields - 4)),
                        Price = Convert.ToDecimal(p.Field <object>(numberOfFields - 5)),
                        toDate = DateTime.FromOADate(Convert.ToDouble(p.Field <object>(numberOfFields - 6))),
                        fromDate = DateTime.FromOADate(Convert.ToDouble(p.Field <object>(numberOfFields - 7)))
                    }).ToList();
                    //insert the content into the db
                    foreach (var c in content)
                    {
                        var rows = unit.Scope.Repository <ContentPrice>().GetAll().Where(x => (x.ProductID == c.productID) && (x.ConnectorID == c.connectorID) && (x.VendorID == c.vendorID)).ToList();
                        if (rows != null)
                        {
                            if (rows.Count != 0)
                            {
                                foreach (var r in rows)
                                {
                                    if (!String.IsNullOrEmpty(c.Label))
                                    {
                                        r.ContentPriceLabel = c.Label;
                                        r.FromDate          = c.fromDate;
                                        r.ToDate            = c.toDate;
                                        r.FixedPrice        = c.Price;
                                    }
                                }
                            }
                            else
                            {
                                //create a new row
                                var product = unit.Scope.Repository <Product>().GetAll().Where(x => x.ProductID == c.productID).SingleOrDefault();
                                if (product != null)
                                {
                                    // find the brandid
                                    var brandID = product.BrandID;
                                    var ContentPriceRuleIndex = 4;
                                    var PriceRuleType         = 1;
                                    var Margin   = "+";
                                    var VendorID = Convert.ToInt32(c.vendorID);

                                    ContentPrice cp = new ContentPrice()
                                    {
                                        VendorID = VendorID, ConnectorID = c.connectorID, BrandID = brandID, ProductID = product.ProductID, Margin = Margin, CreatedBy = Client.User.UserID, CreationTime = DateTime.Now, ContentPriceRuleIndex = ContentPriceRuleIndex, PriceRuleType = PriceRuleType, FromDate = c.fromDate, ToDate = c.toDate, FixedPrice = c.Price, ContentPriceLabel = c.Label
                                    };
                                    unit.Scope.Repository <ContentPrice>().Add(cp);

                                    //          //unit.Save();
                                }
                            }
                        }
                    }
                    unit.Save();
                }
            }
        }
        public ActionResult UpdateAverageMargin(int id, decimal Margin, int?productGroupMappingID, int?productGroupID, int?brandID, int?vendorID)
        {
            using (var unit = GetUnitOfWork())
            {
                int VendorID     = unit.Service <Content>().Get(x => x.ProductID == id && x.ConnectorID == Client.User.ConnectorID.Value).ContentProduct.VendorID;
                var ContentPrice = unit.Service <ContentPrice>().Get(c => c.ProductID == id);

                if (ContentPrice == null)
                {
                    ContentPrice parentContentPrice = unit.Service <ContentPrice>().Get
                                                          (c =>
                                                          ((brandID.HasValue && brandID != 0) ? c.BrandID == brandID.Value : true) &&
                                                          ((productGroupID.HasValue && productGroupID != 0) ? c.ProductGroupID == productGroupID.Value : true) &&
                                                          c.ConnectorID == Client.User.ConnectorID.Value &&
                                                          c.VendorID == VendorID);

                    if (parentContentPrice != null)
                    {
                        ContentPrice newContentPrice = new ContentPrice();
                        newContentPrice.ProductID                 = id;
                        newContentPrice.VendorID                  = parentContentPrice.VendorID;
                        newContentPrice.ConnectorID               = Client.User.ConnectorID.Value;
                        newContentPrice.ContentPriceRuleIndex     = parentContentPrice.ContentPriceRuleIndex;
                        newContentPrice.ComparePricePosition      = parentContentPrice.ComparePricePosition;
                        newContentPrice.CompareSourceID           = parentContentPrice.ComparePricePosition;
                        newContentPrice.ContentPriceCalculationID = parentContentPrice.ContentPriceCalculationID;
                        newContentPrice.CostPriceIncrease         = parentContentPrice.CostPriceIncrease;
                        newContentPrice.FixedPrice                = parentContentPrice.FixedPrice;
                        newContentPrice.FromDate                  = parentContentPrice.FromDate;
                        newContentPrice.Margin = parentContentPrice.Margin;
                        newContentPrice.MaxComparePricePosition = parentContentPrice.MaxComparePricePosition;
                        newContentPrice.MinComparePricePosition = parentContentPrice.MinComparePricePosition;
                        newContentPrice.MinimumQuantity         = parentContentPrice.MinimumQuantity;
                        newContentPrice.PriceRuleType           = parentContentPrice.PriceRuleType;
                        newContentPrice.BottomMargin            = Margin;
                        newContentPrice.UnitPriceIncrease       = parentContentPrice.UnitPriceIncrease;
                        newContentPrice.PriceRuleType           = 1;
                        unit.Service <ContentPrice>().Create(newContentPrice);
                    }
                    else
                    {
                        ContentPrice newContentPrice = new ContentPrice();
                        newContentPrice.ContentPriceRuleIndex = 0;
                        newContentPrice.ProductID             = id;
                        newContentPrice.BottomMargin          = Margin;
                        newContentPrice.Margin        = "%";
                        newContentPrice.VendorID      = VendorID;
                        newContentPrice.ConnectorID   = Client.User.ConnectorID.Value;
                        newContentPrice.PriceRuleType = 1;
                        unit.Service <ContentPrice>().Create(newContentPrice);
                    }
                    unit.Save();
                }
                else
                {
                    ContentPrice.BottomMargin = Margin;
                }

                unit.Save();
            }

            return(GetAverageMarginList(brandID, vendorID, productGroupMappingID, productGroupID));
        }
        public ActionResult Update(
            int productGroupMappingID,
            int productGroupID,
            DateTime?startDate,
            DateTime?endDate,
            decimal?BottomMargin,
            int?MinComparePricePosition,
            int?MaxComparePricePosition,
            string ContentPriceLabel,
            int?brandID,
            int?vendorID,
            int?ContentPriceRuleIndex
            )
        {
            using (var unit = GetUnitOfWork())
            {
                var selectedMapping = unit.Service <ProductGroupMapping>().Get(x => x.ProductGroupMappingID == productGroupMappingID);
                GetMapping(selectedMapping);

                if (!vendorID.HasValue)
                {
                    int productID = _productList.FirstOrDefault();
                    vendorID = unit.Service <Content>().Get(x => x.ProductID == productID && x.ConnectorID == Client.User.ConnectorID.Value).ContentProduct.VendorID;
                }

                var contentPriceOfProductGroup = unit.Service <ContentPrice>().Get(c => c.ProductGroupID == productGroupID && c.ConnectorID == Client.User.ConnectorID);
                if (contentPriceOfProductGroup == null && (BottomMargin.HasValue || MinComparePricePosition.HasValue || MaxComparePricePosition.HasValue))
                {
                    contentPriceOfProductGroup = new ContentPrice();

                    contentPriceOfProductGroup.ProductGroupID        = productGroupID;
                    contentPriceOfProductGroup.ContentPriceRuleIndex = (ContentPriceRuleIndex.HasValue) ? ContentPriceRuleIndex.Value : 0;
                    contentPriceOfProductGroup.ContentPriceLabel     = ContentPriceLabel;

                    contentPriceOfProductGroup.VendorID = vendorID.Value;

                    contentPriceOfProductGroup.ConnectorID = Client.User.ConnectorID.Value;

                    contentPriceOfProductGroup.Margin                  = "%";
                    contentPriceOfProductGroup.VendorID                = vendorID.Value;
                    contentPriceOfProductGroup.FromDate                = (startDate.HasValue) ? startDate.Value.ToUniversalTime() : contentPriceOfProductGroup.FromDate;
                    contentPriceOfProductGroup.ToDate                  = (endDate.HasValue) ? endDate.Value.ToUniversalTime() : contentPriceOfProductGroup.ToDate;
                    contentPriceOfProductGroup.BottomMargin            = (BottomMargin.HasValue) ? BottomMargin.Value : contentPriceOfProductGroup.BottomMargin;
                    contentPriceOfProductGroup.MinComparePricePosition = (MinComparePricePosition.HasValue) ? MinComparePricePosition.Value : contentPriceOfProductGroup.MinComparePricePosition;
                    contentPriceOfProductGroup.MaxComparePricePosition = (MaxComparePricePosition.HasValue) ? MaxComparePricePosition.Value : contentPriceOfProductGroup.MaxComparePricePosition;
                    contentPriceOfProductGroup.BrandID                 = (brandID.HasValue) ? brandID.Value : contentPriceOfProductGroup.BrandID;
                    contentPriceOfProductGroup.ContentPriceRuleIndex   = (ContentPriceRuleIndex.HasValue) ? ContentPriceRuleIndex.Value : contentPriceOfProductGroup.ContentPriceRuleIndex;
                    contentPriceOfProductGroup.PriceRuleType           = 1;

                    unit.Service <ContentPrice>().Create(contentPriceOfProductGroup);
                    unit.Save();
                }
                else
                {
                    contentPriceOfProductGroup.VendorID                = vendorID.Value;
                    contentPriceOfProductGroup.FromDate                = (startDate.HasValue) ? startDate.Value.ToUniversalTime() : contentPriceOfProductGroup.FromDate;
                    contentPriceOfProductGroup.ToDate                  = (endDate.HasValue) ? endDate.Value.ToUniversalTime() : contentPriceOfProductGroup.ToDate;
                    contentPriceOfProductGroup.BottomMargin            = (BottomMargin.HasValue) ? BottomMargin.Value : contentPriceOfProductGroup.BottomMargin;
                    contentPriceOfProductGroup.MinComparePricePosition = (MinComparePricePosition.HasValue) ? MinComparePricePosition.Value : contentPriceOfProductGroup.MinComparePricePosition;
                    contentPriceOfProductGroup.MaxComparePricePosition = (MaxComparePricePosition.HasValue) ? MaxComparePricePosition.Value : contentPriceOfProductGroup.MaxComparePricePosition;
                    contentPriceOfProductGroup.BrandID                 = (brandID.HasValue) ? brandID.Value : contentPriceOfProductGroup.BrandID;
                    contentPriceOfProductGroup.ContentPriceRuleIndex   = (ContentPriceRuleIndex.HasValue) ? ContentPriceRuleIndex.Value : contentPriceOfProductGroup.ContentPriceRuleIndex;
                    contentPriceOfProductGroup.ContentPriceLabel       = ContentPriceLabel;
                    contentPriceOfProductGroup.PriceRuleType           = 1;
                }

                _productList.ForEach(productID =>
                {
                    if (!vendorID.HasValue)
                    {
                        vendorID = unit.Service <Content>().Get(x => x.ProductID == productID && x.ConnectorID == Client.User.ConnectorID.Value).ContentProduct.VendorID;
                    }

                    contentPriceOfProductGroup = unit.Service <ContentPrice>().Get(c => c.ProductID == productID && c.ConnectorID == Client.User.ConnectorID);

                    if (contentPriceOfProductGroup != null)
                    {
                        contentPriceOfProductGroup.VendorID                = vendorID.Value;
                        contentPriceOfProductGroup.FromDate                = (startDate.HasValue) ? startDate.Value.ToUniversalTime() : contentPriceOfProductGroup.FromDate;
                        contentPriceOfProductGroup.ToDate                  = (endDate.HasValue) ? endDate.Value.ToUniversalTime() : contentPriceOfProductGroup.ToDate;
                        contentPriceOfProductGroup.BottomMargin            = (BottomMargin.HasValue) ? BottomMargin.Value : contentPriceOfProductGroup.BottomMargin;
                        contentPriceOfProductGroup.MinComparePricePosition = (MinComparePricePosition.HasValue) ? MinComparePricePosition.Value : contentPriceOfProductGroup.MinComparePricePosition;
                        contentPriceOfProductGroup.MaxComparePricePosition = (MaxComparePricePosition.HasValue) ? MaxComparePricePosition.Value : contentPriceOfProductGroup.MaxComparePricePosition;
                        contentPriceOfProductGroup.BrandID                 = (brandID.HasValue) ? brandID.Value : contentPriceOfProductGroup.BrandID;
                        contentPriceOfProductGroup.ContentPriceRuleIndex   = (ContentPriceRuleIndex.HasValue) ? ContentPriceRuleIndex.Value : contentPriceOfProductGroup.ContentPriceRuleIndex;
                        contentPriceOfProductGroup.ContentPriceLabel       = ContentPriceLabel;
                        contentPriceOfProductGroup.PriceRuleType           = 1;
                    }

                    unit.Save();
                });
            }
            return(Json(new
            {
                success = true
            }));
        }