Ejemplo n.º 1
0
        /// <summary>
        /// Updates the ProductVariantPricelist
        /// </summary>
        /// <param name="productVariantPricelist">The product variant pricelist</param>
        public void UpdateProductVariantPricelist(ProductVariantPricelist productVariantPricelist)
        {
            if (productVariantPricelist == null)
                throw new ArgumentNullException("productVariantPricelist");

            if (!_context.IsAttached(productVariantPricelist))
                _context.ProductVariantPricelists.Attach(productVariantPricelist);

            _context.SaveChanges();
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Inserts a ProductVariantPricelist
        /// </summary>
        /// <param name="productVariantPricelist">The product variant pricelist</param>
        public void InsertProductVariantPricelist(ProductVariantPricelist productVariantPricelist)
        {
            if (productVariantPricelist == null)
                throw new ArgumentNullException("productVariantPricelist");

            _context.ProductVariantPricelists.AddObject(productVariantPricelist);
            _context.SaveChanges();
        }
Ejemplo n.º 3
0
        private string CreatePricelistContents()
        {
            string strContents = string.Empty;

            var  productVariants       = new List <ProductVariant>();
            bool blnOverrideAdjustment = this.OverrideIndivAdjustment;

            switch (this.ExportMode)
            {
            case PriceListExportModeEnum.All:
            {
                blnOverrideAdjustment = true;
                foreach (Product product in ProductManager.GetAllProducts(false))
                {
                    productVariants.AddRange(ProductManager.GetProductVariantsByProductId(product.ProductId, false));
                }
            }
            break;

            case PriceListExportModeEnum.AssignedProducts:
            {
                productVariants = ProductManager.GetProductVariantsByPricelistId(this.PricelistId);
            }
            break;

            default:
                break;
            }

            // create new file
            // write header, if provided
            if (!String.IsNullOrEmpty(this.Header))
            {
                strContents += this.Header;
                if (!this.Header.EndsWith("\n"))
                {
                    strContents += "\n";
                }
            }

            // write body
            foreach (ProductVariant productVariant in productVariants)
            {
                // calculate price adjustments
                decimal newPrice = decimal.Zero;

                // if export mode is all, then calculate price
                if (blnOverrideAdjustment)
                {
                    newPrice = GetAdjustedPrice(productVariant.Price, this.PriceAdjustmentType, PriceAdjustment);
                }
                else
                {
                    ProductVariantPricelist productVariantPricelist = ProductManager.GetProductVariantPricelist(productVariant.ProductVariantId, this.PricelistId);
                    if (productVariantPricelist != null)
                    {
                        newPrice = GetAdjustedPrice(productVariant.Price, productVariantPricelist.PriceAdjustmentType, productVariantPricelist.PriceAdjustment);
                    }
                }
                strContents += replaceMessageTemplateTokens(productVariant, this.Body,
                                                            this.FormatLocalization, new System.Collections.Specialized.NameValueCollection(), AffiliateId, newPrice);
                if (!this.Body.EndsWith("\n"))
                {
                    strContents += "\n";
                }
            }

            // write footer, if provided
            if (!String.IsNullOrEmpty(this.Footer))
            {
                strContents += this.Header;
                if (!this.Footer.EndsWith("\n"))
                {
                    strContents += "\n";
                }
            }

            return(strContents);
        }
Ejemplo n.º 4
0
        private static ProductVariantPricelist DBMapping(DBProductVariantPricelist dbItem)
        {
            if (dbItem == null)
                return null;

            ProductVariantPricelist item = new ProductVariantPricelist();
            item.ProductVariantPricelistID = dbItem.ProductVariantPricelistID;
            item.ProductVariantID = dbItem.ProductVariantID;
            item.PricelistID = dbItem.PricelistID;
            item.PriceAdjustmentTypeID = dbItem.PriceAdjustmentTypeID;
            item.PriceAdjustment = dbItem.PriceAdjustment;
            item.UpdatedOn = dbItem.UpdatedOn;

            return item;
        }
Ejemplo n.º 5
0
        protected void SavePricelistChanges(int priceListId)
        {
            foreach (GridViewRow objRow in gvProductVariants.Rows)
            {
                if (objRow.RowType == DataControlRowType.DataRow)
                {
                    CheckBox chkSelected = objRow.FindControl("chkSelected") as CheckBox;
                    DropDownList ddlPriceAdjustmentType = objRow.FindControl("ddlPriceAdjustmentType") as DropDownList;
                    DecimalTextBox txtPriceAdjustment = objRow.FindControl("txtPriceAdjustment") as DecimalTextBox;
                    HiddenField hfProductVariantPricelistId = objRow.FindControl("hfProductVariantPricelistId") as HiddenField;
                    HiddenField hfProductVariantId = objRow.FindControl("hfProductVariantId") as HiddenField;

                    int productVariantPricelistId = 0;
                    int.TryParse(hfProductVariantPricelistId.Value, out productVariantPricelistId);

                    ProductVariantPricelist productVariantPricelist = this.ProductService.GetProductVariantPricelistById(productVariantPricelistId);
                    if (chkSelected.Checked)
                    {
                        int productVariantId = 0;
                        int.TryParse(hfProductVariantId.Value, out productVariantId);

                        PriceAdjustmentTypeEnum priceAdjustmentType = (PriceAdjustmentTypeEnum)Enum.ToObject(typeof(PriceAdjustmentTypeEnum), int.Parse(ddlPriceAdjustmentType.SelectedItem.Value));
                        decimal priceAdjustment = txtPriceAdjustment.Value;

                        if (productVariantPricelist != null)
                        {
                            productVariantPricelist.ProductVariantId = productVariantId;
                            productVariantPricelist.PricelistId = priceListId;
                            productVariantPricelist.PriceAdjustmentTypeId = (int)priceAdjustmentType;
                            productVariantPricelist.PriceAdjustment = priceAdjustment;
                            productVariantPricelist.UpdatedOn = DateTime.UtcNow;
                            this.ProductService.UpdateProductVariantPricelist(productVariantPricelist);
                        }
                        else
                        {
                            productVariantPricelist = new ProductVariantPricelist();
                            productVariantPricelist.ProductVariantId = productVariantId;
                            productVariantPricelist.PricelistId = priceListId;
                            productVariantPricelist.PriceAdjustmentTypeId = (int)priceAdjustmentType;
                            productVariantPricelist.PriceAdjustment = priceAdjustment;
                            productVariantPricelist.UpdatedOn = DateTime.UtcNow;
                            this.ProductService.InsertProductVariantPricelist(productVariantPricelist);
                        }
                    }
                    else
                    {
                        if (productVariantPricelist != null)
                        {
                            this.ProductService.DeleteProductVariantPricelist(productVariantPricelistId);
                        }
                    }
                }
            }
        }