Ejemplo n.º 1
0
        /// <summary>
        /// Patch CatalogBase type
        /// </summary>
        /// <param name="source"></param>
        /// <param name="target"></param>
        public static void Patch(this LineItemEntity source, LineItemEntity target)
        {
            if (target == null)
            {
                throw new ArgumentNullException("target");
            }


            var patchInjectionPolicy = new PatchInjection <LineItemEntity>(x => x.BasePrice, x => x.Price,
                                                                           x => x.Quantity, x => x.DiscountAmount, x => x.Tax, x => x.Height, x => x.Length,
                                                                           x => x.Width, x => x.MeasureUnit, x => x.WeightUnit, x => x.Weight, x => x.TaxType, x => x.IsCancelled, x => x.CancelledDate, x => x.CancelReason);

            target.InjectFrom(patchInjectionPolicy, source);


            if (!source.Discounts.IsNullCollection())
            {
                source.Discounts.Patch(target.Discounts, new DiscountComparer(), (sourceDiscount, targetDiscount) => sourceDiscount.Patch(targetDiscount));
            }

            if (!source.TaxDetails.IsNullCollection())
            {
                var taxDetailComparer = AnonymousComparer.Create((TaxDetailEntity x) => x.Name);
                source.TaxDetails.Patch(target.TaxDetails, taxDetailComparer, (sourceTaxDetail, targetTaxDetail) => sourceTaxDetail.Patch(targetTaxDetail));
            }
        }
        public static LineItemEntity ToDataModel(this LineItem lineItem, PrimaryKeyResolvingMap pkMap)
        {
            if (lineItem == null)
            {
                throw new ArgumentNullException("lineItem");
            }

            var retVal = new LineItemEntity();

            pkMap.AddPair(lineItem, retVal);

            retVal.InjectFrom(lineItem);
            retVal.Currency = lineItem.Currency.ToString();
            if (lineItem.TaxDetails != null)
            {
                retVal.TaxDetails = new ObservableCollection <TaxDetailEntity>();
                retVal.TaxDetails.AddRange(lineItem.TaxDetails.Select(x => x.ToDataModel()));
            }

            if (lineItem.Discounts != null)
            {
                retVal.Discounts = new ObservableCollection <DiscountEntity>();
                retVal.Discounts.AddRange(lineItem.Discounts.Select(x => x.ToDataModel(pkMap)));
            }
            return(retVal);
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Patch CatalogBase type
        /// </summary>
        /// <param name="source"></param>
        /// <param name="target"></param>
        public static void Patch(this LineItemEntity source, LineItemEntity target)
        {
            if (target == null)
            {
                throw new ArgumentNullException("target");
            }

            var patchInjection = new PatchInjection <LineItemEntity>(x => x.Quantity, x => x.SalePrice, x => x.PlacedPrice, x => x.ListPrice, x => x.TaxIncluded, x => x.TaxTotal);

            target.InjectFrom(patchInjection, source);

            if (!source.TaxDetails.IsNullCollection())
            {
                var taxDetailComparer = AnonymousComparer.Create((TaxDetailEntity x) => x.Name);
                source.TaxDetails.Patch(target.TaxDetails, taxDetailComparer, (sourceTaxDetail, targetTaxDetail) => sourceTaxDetail.Patch(targetTaxDetail));
            }
        }
Ejemplo n.º 4
0
        public static LineItemEntity ToDataModel(this LineItem lineItem)
        {
            if (lineItem == null)
            {
                throw new ArgumentNullException("lineItem");
            }

            var retVal = new LineItemEntity();

            retVal.InjectFrom(lineItem);
            retVal.Currency = lineItem.Currency.ToString();
            if (lineItem.TaxDetails != null)
            {
                retVal.TaxDetails = new ObservableCollection <TaxDetailEntity>();
                retVal.TaxDetails.AddRange(lineItem.TaxDetails.Select(x => x.ToDataModel()));
            }
            return(retVal);
        }