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.Discount != null) { retVal.Discounts = new ObservableCollection<DiscountEntity>(new DiscountEntity[] { lineItem.Discount.ToDataModel() }); } if(lineItem.TaxDetails != null) { retVal.TaxDetails = new ObservableCollection<TaxDetailEntity>(); retVal.TaxDetails.AddRange(lineItem.TaxDetails.Select(x=>x.ToDataModel())); } return retVal; }
public virtual void Patch(LineItemEntity target) { if (target == null) { throw new ArgumentNullException(nameof(target)); } target.Quantity = Quantity; target.Weight = Weight; target.Height = Height; target.Width = Width; target.MeasureUnit = MeasureUnit; target.WeightUnit = WeightUnit; target.Length = Length; target.TaxType = TaxType; target.IsCancelled = IsCancelled; target.CancelledDate = CancelledDate; target.CancelReason = CancelReason; target.Comment = Comment; if (!(GetNonCalculatablePrices().All(x => x == 0m) && target.GetNonCalculatablePrices().Any(x => x != 0m))) { target.TaxPercentRate = TaxPercentRate; target.Price = Price; target.DiscountAmount = DiscountAmount; target.PriceWithTax = PriceWithTax; target.DiscountAmountWithTax = DiscountAmountWithTax; target.TaxTotal = TaxTotal; } if (!Discounts.IsNullCollection()) { var discountComparer = AnonymousComparer.Create((DiscountEntity x) => x.PromotionId); Discounts.Patch(target.Discounts, discountComparer, (sourceDiscount, targetDiscount) => sourceDiscount.Patch(targetDiscount)); } if (!TaxDetails.IsNullCollection()) { var taxDetailComparer = AnonymousComparer.Create((TaxDetailEntity x) => x.Name); TaxDetails.Patch(target.TaxDetails, taxDetailComparer, (sourceTaxDetail, targetTaxDetail) => sourceTaxDetail.Patch(targetTaxDetail)); } }
public virtual void Patch(LineItemEntity target) { if (target == null) { throw new ArgumentNullException("target"); } target.Price = this.Price; target.PriceWithTax = this.PriceWithTax; target.DiscountAmount = this.DiscountAmount; target.DiscountAmountWithTax = this.DiscountAmountWithTax; target.Quantity = this.Quantity; target.TaxTotal = this.TaxTotal; target.TaxPercentRate = this.TaxPercentRate; target.Weight = this.Weight; target.Height = this.Height; target.Width = this.Width; target.MeasureUnit = this.MeasureUnit; target.WeightUnit = this.WeightUnit; target.Length = this.Length; target.TaxType = this.TaxType; target.IsCancelled = this.IsCancelled; target.CancelledDate = this.CancelledDate; target.CancelReason = this.CancelReason; target.Comment = this.Comment; if (!this.Discounts.IsNullCollection()) { var discountComparer = AnonymousComparer.Create((DiscountEntity x) => x.PromotionId); this.Discounts.Patch(target.Discounts, discountComparer, (sourceDiscount, targetDiscount) => sourceDiscount.Patch(targetDiscount)); } if (!this.TaxDetails.IsNullCollection()) { var taxDetailComparer = AnonymousComparer.Create((TaxDetailEntity x) => x.Name); this.TaxDetails.Patch(target.TaxDetails, taxDetailComparer, (sourceTaxDetail, targetTaxDetail) => sourceTaxDetail.Patch(targetTaxDetail)); } }
/// <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)); } }