Пример #1
0
        private double EvalProperty(ShippingContraintProperty property, IList <Tuple <int, IShippingInfo> > ShippingInfos, Decimal ItemsTotal)
        {
            // Ensure ShippingInfos not null
            var shippingInfos = ShippingInfos ?? new List <Tuple <int, IShippingInfo> >();

            //  shippingInfos :
            //  Item1 => Qty
            //  Item2 => IShippingInfo
            switch (property)
            {
            case ShippingContraintProperty.TotalPrice:
                return(Convert.ToDouble(ItemsTotal));

            case ShippingContraintProperty.TotalWeight:
                if (!shippingInfos.Any())
                {
                    return(0);
                }
                return(shippingInfos.Sum(i => i.Item1 * i.Item2.Weight));

            case ShippingContraintProperty.TotalVolume:
                if (!shippingInfos.Any())
                {
                    return(0);
                }
                return(shippingInfos.Sum(i => i.Item1 * i.Item2.Length * i.Item2.Width * i.Item2.Height));

            case ShippingContraintProperty.ItemLongestDimension:
                if (!shippingInfos.Any())
                {
                    return(0);
                }
                return(shippingInfos.Max(i => new double[] { i.Item2.Length, i.Item2.Width, i.Item2.Height }.Max()));

            case ShippingContraintProperty.MaxItemLength:
                if (!shippingInfos.Any())
                {
                    return(0);
                }
                return(shippingInfos.Max(i => i.Item2.Length));

            case ShippingContraintProperty.MaxItemWidth:
                if (!shippingInfos.Any())
                {
                    return(0);
                }
                return(shippingInfos.Max(i => i.Item2.Width));

            case ShippingContraintProperty.MaxItemHeight:
                if (!shippingInfos.Any())
                {
                    return(0);
                }
                return(shippingInfos.Max(i => i.Item2.Height));

            default:
                return(0);
            }
        }
Пример #2
0
        private double EvalProperty(ShippingContraintProperty property, IList<Tuple<int, IShippingInfo>> ShippingInfos, Decimal ItemsTotal)
        {
            // Ensure ShippingInfos not null
            var shippingInfos = ShippingInfos ?? new List<Tuple<int, IShippingInfo>>();

            //  shippingInfos :
            //  Item1 => Qty
            //  Item2 => IShippingInfo
            switch (property) {
                case ShippingContraintProperty.TotalPrice:
                    return Convert.ToDouble(ItemsTotal);
                case ShippingContraintProperty.TotalWeight:
                    if (!shippingInfos.Any()) {
                        return 0;
                    }
                    return shippingInfos.Sum(i => i.Item1 * i.Item2.Weight);
                case ShippingContraintProperty.TotalVolume:
                    if (!shippingInfos.Any()) {
                        return 0;
                    }
                    return shippingInfos.Sum(i => i.Item1 * i.Item2.Length * i.Item2.Width * i.Item2.Height);
                case ShippingContraintProperty.ItemLongestDimension:
                    if (!shippingInfos.Any()) {
                        return 0;
                    }
                    return shippingInfos.Max(i => new double[] { i.Item2.Length, i.Item2.Width, i.Item2.Height }.Max());
                case ShippingContraintProperty.MaxItemLength:
                    if (!shippingInfos.Any()) {
                        return 0;
                    }
                    return shippingInfos.Max(i => i.Item2.Length);
                case ShippingContraintProperty.MaxItemWidth:
                    if (!shippingInfos.Any()) {
                        return 0;
                    }
                    return shippingInfos.Max(i => i.Item2.Width);
                case ShippingContraintProperty.MaxItemHeight:
                    if (!shippingInfos.Any()) {
                        return 0;
                    }
                    return shippingInfos.Max(i => i.Item2.Height);
                default:
                    return 0;
            }
        }