Ejemplo n.º 1
0
        public virtual void Patch(ShipmentEntity target)
        {
            if (target == null)
            {
                throw new ArgumentNullException(nameof(target));
            }

            target.Fee                   = Fee;
            target.FeeWithTax            = FeeWithTax;
            target.FulfillmentCenterId   = FulfillmentCenterId;
            target.FulfillmentCenterName = FulfillmentCenterName;
            target.ShipmentMethodCode    = ShipmentMethodCode;
            target.Total                 = Total;
            target.TotalWithTax          = TotalWithTax;
            target.TaxTotal              = TaxTotal;
            target.Price                 = Price;
            target.PriceWithTax          = PriceWithTax;
            target.DiscountAmount        = DiscountAmount;
            target.DiscountAmountWithTax = DiscountAmountWithTax;
            target.TaxPercentRate        = TaxPercentRate;
            target.TaxIncluded           = TaxIncluded;
            target.Currency              = Currency;
            target.WeightUnit            = WeightUnit;
            target.WeightValue           = WeightValue;
            target.DimensionHeight       = DimensionHeight;
            target.DimensionLength       = DimensionLength;
            target.DimensionUnit         = DimensionUnit;
            target.DimensionWidth        = DimensionWidth;
            target.TaxType               = TaxType;
            target.ShipmentMethodOption  = ShipmentMethodOption;

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

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

            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));
            }

            if (!DynamicPropertyObjectValues.IsNullCollection())
            {
                DynamicPropertyObjectValues.Patch(target.DynamicPropertyObjectValues, (sourceDynamicPropertyObjectValues, targetDynamicPropertyObjectValues) => sourceDynamicPropertyObjectValues.Patch(targetDynamicPropertyObjectValues));
            }
        }
Ejemplo n.º 2
0
        public override void Patch(OperationEntity operation)
        {
            base.Patch(operation);

            var target = operation as PaymentInEntity;

            if (target == null)
            {
                throw new ArgumentException(@"operation argument must be of type PaymentInEntity", nameof(operation));
            }

            target.Amount                = Amount;
            target.Price                 = Price;
            target.PriceWithTax          = PriceWithTax;
            target.DiscountAmount        = DiscountAmount;
            target.DiscountAmountWithTax = DiscountAmountWithTax;
            target.TaxType               = TaxType;
            target.TaxPercentRate        = TaxPercentRate;
            target.TaxTotal              = TaxTotal;
            target.Total                 = Total;
            target.TotalWithTax          = TotalWithTax;

            target.CustomerId       = CustomerId;
            target.CustomerName     = CustomerName;
            target.OrganizationId   = OrganizationId;
            target.OrganizationName = OrganizationName;
            target.GatewayCode      = GatewayCode;
            target.Purpose          = Purpose;
            target.OuterId          = OuterId;
            target.Status           = Status;
            target.AuthorizedDate   = AuthorizedDate;
            target.CapturedDate     = CapturedDate;
            target.VoidedDate       = VoidedDate;
            target.IsCancelled      = IsCancelled;
            target.CancelledDate    = CancelledDate;
            target.CancelReason     = CancelReason;
            target.Sum = Sum;

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

            if (!TaxDetails.IsNullCollection())
            {
                var taxDetailComparer = AnonymousComparer.Create((TaxDetailEntity x) => x.Name);
                TaxDetails.Patch(target.TaxDetails, taxDetailComparer, (sourceTaxDetail, targetTaxDetail) => sourceTaxDetail.Patch(targetTaxDetail));
            }

            if (!Discounts.IsNullCollection())
            {
                var discountComparer = AnonymousComparer.Create((DiscountEntity x) => x.PromotionId);
                Discounts.Patch(target.Discounts, discountComparer, (sourceDiscount, targetDiscount) => sourceDiscount.Patch(targetDiscount));
            }

            if (!Transactions.IsNullCollection())
            {
                Transactions.Patch(target.Transactions, (sourceTran, targetTran) => sourceTran.Patch(targetTran));
            }
        }
        public virtual void Patch(LineItemEntity target)
        {
            if (target == null)
            {
                throw new ArgumentNullException(nameof(target));
            }

            target.ListPrice        = ListPrice;
            target.ListPriceWithTax = ListPriceWithTax;
            target.SalePrice        = SalePrice;
            target.SalePriceWithTax = SalePriceWithTax;
            target.Fee                    = Fee;
            target.FeeWithTax             = FeeWithTax;
            target.DiscountAmount         = DiscountAmount;
            target.DiscountAmountWithTax  = DiscountAmountWithTax;
            target.Quantity               = Quantity;
            target.TaxTotal               = TaxTotal;
            target.TaxPercentRate         = TaxPercentRate;
            target.Weight                 = Weight;
            target.Height                 = Height;
            target.Width                  = Width;
            target.MeasureUnit            = MeasureUnit;
            target.WeightUnit             = WeightUnit;
            target.Length                 = Length;
            target.TaxType                = TaxType;
            target.Comment                = Comment;
            target.IsReadOnly             = IsReadOnly;
            target.ValidationType         = ValidationType;
            target.PriceId                = PriceId;
            target.LanguageCode           = LanguageCode;
            target.IsReccuring            = IsReccuring;
            target.IsGift                 = IsGift;
            target.ImageUrl               = ImageUrl;
            target.ProductId              = ProductId;
            target.ProductType            = ProductType;
            target.ShipmentMethodCode     = ShipmentMethodCode;
            target.RequiredShipping       = RequiredShipping;
            target.ProductType            = ProductType;
            target.FulfilmentLocationCode = FulfilmentLocationCode;
            target.FulfillmentCenterId    = FulfillmentCenterId;
            target.FulfillmentCenterName  = FulfillmentCenterName;

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

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

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

                TaxDetails.Patch(target.TaxDetails, taxDetailComparer, (sourceTaxDetail, targetTaxDetail) => sourceTaxDetail.Patch(targetTaxDetail));
            }
        }
Ejemplo n.º 4
0
        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));
            }

            if (!DynamicPropertyObjectValues.IsNullCollection())
            {
                DynamicPropertyObjectValues.Patch(target.DynamicPropertyObjectValues, (sourceDynamicPropertyObjectValues, targetDynamicPropertyObjectValues) => sourceDynamicPropertyObjectValues.Patch(targetDynamicPropertyObjectValues));
            }
        }
Ejemplo n.º 5
0
        public virtual void Patch(PaymentEntity target)
        {
            if (target == null)
            {
                throw new ArgumentNullException(nameof(target));
            }

            target.Amount             = Amount;
            target.PaymentGatewayCode = PaymentGatewayCode;
            target.Price                 = Price;
            target.PriceWithTax          = PriceWithTax;
            target.DiscountAmount        = DiscountAmount;
            target.DiscountAmountWithTax = DiscountAmountWithTax;
            target.TaxType               = TaxType;
            target.TaxPercentRate        = TaxPercentRate;
            target.TaxTotal              = TaxTotal;
            target.Total                 = Total;
            target.TotalWithTax          = TotalWithTax;
            target.Purpose               = Purpose;
            target.Currency              = Currency;

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

            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));
            }

            if (!DynamicPropertyObjectValues.IsNullCollection())
            {
                DynamicPropertyObjectValues.Patch(target.DynamicPropertyObjectValues, (sourceDynamicPropertyObjectValues, targetDynamicPropertyObjectValues) => sourceDynamicPropertyObjectValues.Patch(targetDynamicPropertyObjectValues));
            }
        }
Ejemplo n.º 6
0
        public override void Patch(OperationEntity operation)
        {
            var target = operation as ShipmentEntity;

            if (target == null)
            {
                throw new ArgumentException(@"operation argument must be of type ShipmentEntity", nameof(operation));
            }

            var isNeedPatch = !(GetNonCalculatablePrices().Any(x => x == 0m) && target.GetNonCalculatablePrices().Any(x => x != 0m));

            base.NeedPatchSum = isNeedPatch;
            base.Patch(operation);

            target.FulfillmentCenterId   = FulfillmentCenterId;
            target.FulfillmentCenterName = FulfillmentCenterName;
            target.OrganizationId        = OrganizationId;
            target.OrganizationName      = OrganizationName;
            target.EmployeeId            = EmployeeId;
            target.EmployeeName          = EmployeeName;
            target.ShipmentMethodCode    = ShipmentMethodCode;
            target.ShipmentMethodOption  = ShipmentMethodOption;
            target.Height      = Height;
            target.Length      = Length;
            target.Weight      = Weight;
            target.Height      = Height;
            target.Width       = Width;
            target.MeasureUnit = MeasureUnit;
            target.WeightUnit  = WeightUnit;
            target.Length      = Length;
            target.TaxType     = TaxType;

            if (isNeedPatch)
            {
                target.Price                 = Price;
                target.PriceWithTax          = PriceWithTax;
                target.DiscountAmount        = DiscountAmount;
                target.DiscountAmountWithTax = DiscountAmountWithTax;
                target.TaxPercentRate        = TaxPercentRate;
                target.TaxTotal              = TaxTotal;
                target.Total                 = Total;
                target.TotalWithTax          = TotalWithTax;
            }

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

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

            if (!Discounts.IsNullCollection())
            {
                var discountComparer = AnonymousComparer.Create((DiscountEntity x) => x.PromotionId);
                Discounts.Patch(target.Discounts, discountComparer, (sourceDiscount, targetDiscount) => sourceDiscount.Patch(targetDiscount));
            }

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

            if (!Packages.IsNullCollection())
            {
                Packages.Patch(target.Packages, (sourcePackage, targetPackage) => sourcePackage.Patch(targetPackage));
            }

            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(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.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())
            {
                foreach (var shipment in Shipments.Where(x => !x.Items.IsNullCollection()))
                {
                    //Need to remove all items from the shipment with references to non-existing line items.
                    //eft join shipment.Items with cart.Items to detect shipment items are referenced to no longer exist line items
                    var toRemoveItems = shipment.Items.GroupJoin(Items,
                                                                 shipmentItem => shipmentItem.LineItemId ?? shipmentItem.LineItem?.Id,
                                                                 lineItem => lineItem.Id,
                                                                 (shipmentItem, lineItem) => new { ShipmentItem = shipmentItem, LineItem = lineItem.SingleOrDefault() })
                                        .Where(x => x.LineItem == null)
                                        .Select(x => x.ShipmentItem)
                                        .ToArray();
                    foreach (var toRemoveItem in toRemoveItems)
                    {
                        shipment.Items.Remove(toRemoveItem);
                    }
                    //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 shipmentItem in shipment.Items)
                    {
                        if (shipmentItem.LineItem != null)
                        {
                            shipmentItem.LineItem = target.Items.FirstOrDefault(x => x == shipmentItem.LineItem) ?? shipmentItem.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));
            }

            if (!Coupons.IsNullCollection())
            {
                var couponComparer = AnonymousComparer.Create((CouponEntity x) => x.Code);
                Coupons.Patch(target.Coupons, couponComparer, (sourceCoupon, targetCoupon) => { return; });
            }
        }
        public override void Patch(OperationEntity operation)
        {
            var target = operation as CustomerOrderEntity;

            if (target == null)
            {
                throw new ArgumentException(@"operation argument must be of type CustomerOrderEntity",
                                            nameof(operation));
            }

            target.CustomerId          = CustomerId;
            target.CustomerName        = CustomerName;
            target.StoreId             = StoreId;
            target.StoreName           = StoreName;
            target.OrganizationId      = OrganizationId;
            target.OrganizationName    = OrganizationName;
            target.EmployeeId          = EmployeeId;
            target.EmployeeName        = EmployeeName;
            target.IsPrototype         = IsPrototype;
            target.SubscriptionNumber  = SubscriptionNumber;
            target.SubscriptionId      = SubscriptionId;
            target.PurchaseOrderNumber = PurchaseOrderNumber;
            target.LanguageCode        = LanguageCode;

            // Checks whether calculation of sum is needed to pass the result to the property of base class before calling of base.Patch
            var needPatchPrices = !(GetNonCalculatablePrices().All(x => x == 0m) &&
                                    target.GetNonCalculatablePrices().Any(x => x != 0m));

            if (needPatchPrices)
            {
                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.TaxPercentRate       = TaxPercentRate;
            }

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

            if (!Shipments.IsNullCollection())
            {
                foreach (var shipment in Shipments.Where(x => !x.Items.IsNullCollection()))
                {
                    //Need to remove all items from the shipment with references to non-existing line items.
                    //Left join shipment.Items with cart.Items to detect shipment items are referenced to no longer exist line items
                    var toRemoveItems = shipment.Items.GroupJoin(Items,
                                                                 shipmentItem => shipmentItem.LineItemId ?? shipmentItem.LineItem?.Id,
                                                                 lineItem => lineItem.Id,
                                                                 (shipmentItem, lineItem) => new
                    {
                        ShipmentItem = shipmentItem,
                        LineItem     = lineItem.SingleOrDefault()
                    })
                                        .Where(x => x.LineItem == null)
                                        .Select(x => x.ShipmentItem)
                                        .ToArray();
                    foreach (var toRemoveItem in toRemoveItems)
                    {
                        shipment.Items.Remove(toRemoveItem);
                    }

                    //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 shipmentItem in shipment.Items)
                    {
                        if (shipmentItem.LineItem != null)
                        {
                            shipmentItem.LineItem = target.Items.FirstOrDefault(x => x == shipmentItem.LineItem) ??
                                                    shipmentItem.LineItem;
                        }
                    }
                }

                Shipments.Patch(target.Shipments,
                                (sourceShipment, targetShipment) => sourceShipment.Patch(targetShipment));
            }

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

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

            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));
            }

            if (!DynamicPropertyObjectValues.IsNullCollection())
            {
                DynamicPropertyObjectValues.Patch(target.DynamicPropertyObjectValues, (sourceDynamicPropertyObjectValues, targetDynamicPropertyObjectValues) => sourceDynamicPropertyObjectValues.Patch(targetDynamicPropertyObjectValues));
            }

            base.Patch(operation);
        }
Ejemplo n.º 9
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));
            }
        }
Ejemplo n.º 10
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;

            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())
            {
                var addressComparer = AbstractTypeFactory <AddressComparer> .TryCreateInstance();

                Addresses.Patch(target.Addresses, addressComparer, (sourceAddress, targetAddress) => sourceAddress.Patch(targetAddress));
            }

            if (!Shipments.IsNullCollection())
            {
                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));
            }
        }