Beispiel #1
0
        public virtual void Patch(ShoppingCartEntity target)
        {
            if (target == null)
            {
                throw new ArgumentNullException(nameof(target));
            }

            target.Fee                  = Fee;
            target.FeeWithTax           = FeeWithTax;
            target.Status               = Status;
            target.Currency             = Currency;
            target.ValidationType       = ValidationType;
            target.CustomerId           = CustomerId;
            target.CustomerName         = CustomerName;
            target.IsAnonymous          = IsAnonymous;
            target.IsRecuring           = IsRecuring;
            target.LanguageCode         = LanguageCode;
            target.Comment              = Comment;
            target.OrganizationId       = OrganizationId;
            target.Total                = Total;
            target.SubTotal             = SubTotal;
            target.SubTotalWithTax      = SubTotalWithTax;
            target.ShippingTotal        = ShippingTotal;
            target.ShippingTotalWithTax = ShippingTotalWithTax;
            target.PaymentTotal         = PaymentTotal;
            target.PaymentTotalWithTax  = PaymentTotalWithTax;
            target.HandlingTotal        = HandlingTotal;
            target.HandlingTotalWithTax = HandlingTotalWithTax;
            target.DiscountTotal        = DiscountTotal;
            target.DiscountTotalWithTax = DiscountTotalWithTax;
            target.DiscountAmount       = DiscountAmount;
            target.TaxTotal             = TaxTotal;
            target.Coupon               = Coupon;
            target.TaxPercentRate       = TaxPercentRate;
            target.Type                 = Type;
            target.Name                 = Name;

            if (!Items.IsNullCollection())
            {
                Items.Patch(target.Items, (sourceItem, targetItem) => sourceItem.Patch(targetItem));
            }

            if (!Payments.IsNullCollection())
            {
                Payments.Patch(target.Payments, (sourcePayment, targetPayment) => sourcePayment.Patch(targetPayment));
            }

            if (!Addresses.IsNullCollection())
            {
                Addresses.Patch(target.Addresses, (sourceAddress, targetAddress) => sourceAddress.Patch(targetAddress));
            }

            if (!Shipments.IsNullCollection())
            {
                //Trying to set appropriator lineItem  from EF dynamic proxy lineItem to avoid EF exception (if shipmentItem.LineItem is new object with Id for already exist LineItem)
                foreach (var sourceShipmentItem in Shipments.SelectMany(x => x.Items))
                {
                    if (sourceShipmentItem.LineItem != null)
                    {
                        sourceShipmentItem.LineItem = target.Items.FirstOrDefault(x => x == sourceShipmentItem.LineItem) ?? sourceShipmentItem.LineItem;
                    }
                }
                Shipments.Patch(target.Shipments, (sourceShipment, targetShipment) => sourceShipment.Patch(targetShipment));
            }

            if (!TaxDetails.IsNullCollection())
            {
                var taxDetailComparer = AbstractTypeFactory <TaxDetailEntityComparer> .TryCreateInstance();

                TaxDetails.Patch(target.TaxDetails, taxDetailComparer, (sourceTaxDetail, targetTaxDetail) => sourceTaxDetail.Patch(targetTaxDetail));
            }

            if (!Discounts.IsNullCollection())
            {
                var discountComparer = AbstractTypeFactory <DiscountEntityComparer> .TryCreateInstance();

                Discounts.Patch(target.Discounts, discountComparer, (sourceDiscount, targetDiscount) => sourceDiscount.Patch(targetDiscount));
            }
        }