Ejemplo n.º 1
0
 public static void PrepareContentUnitMeasure(this ProductOverviewModel model)
 {
     if (model.ContentUnitPriceMultiplicator > 0 && model.ContentUnitMeasureID > 0)
     {
         var contentUnitMeasure = RP.GetContentUnitMeasureById(model.ContentUnitMeasureID);
         model.ContentUnitName  = contentUnitMeasure.DisplayName;
         model.ContentUnitPrice = Math.Truncate(model.Price * model.ContentUnitPriceMultiplicator * 100) / 100;
     }
 }
        private static void PrepareContentUnitMeasure(Dictionary <int, string> s, PIsheme sheme, Product product)
        {
            var unitOfMeasure         = s[sheme.UnitOfMeasure];
            var quantityUnitOfMeasure = s[sheme.QuantityUnitOfMeasure];

            if (string.IsNullOrEmpty(unitOfMeasure) || string.IsNullOrEmpty(quantityUnitOfMeasure))
            {
                return;
            }

            var contentUnitMeasureMap = RP.GetContentUnitMeasureMaps().FirstOrDefault(x => x.Synonymous.Contains("|" + unitOfMeasure + "|"));

            if (contentUnitMeasureMap == null)
            {
                return;
            }

            var contentUnitMeasure = RP.GetContentUnitMeasureById(contentUnitMeasureMap.ContentUnitMeasureID);

            if (contentUnitMeasure == null)
            {
                return;
            }

            decimal capacity         = 0;
            var     decimalSeparator = CultureInfo.CurrentCulture.NumberFormat.NumberDecimalSeparator;

            quantityUnitOfMeasure = decimalsOnly.Replace(quantityUnitOfMeasure, "");
            if (!Decimal.TryParse(quantityUnitOfMeasure.Replace(".", decimalSeparator).Replace(",", decimalSeparator), out capacity))
            {
                return;
            }
            if (capacity == 0)
            {
                return;
            }
            product.ContentUnitMeasureID          = contentUnitMeasure.ID;
            product.ContentUnitPriceMultiplicator = contentUnitMeasureMap.Multiplicator / capacity;
        }