public static ShipmentEntity ToDataModel(this Shipment shipment, ShoppingCartEntity cartEntity, PrimaryKeyResolvingMap pkMap) { if (shipment == null) throw new ArgumentNullException("shipment"); var retVal = new ShipmentEntity(); pkMap.AddPair(shipment, retVal); retVal.InjectFrom(shipment); retVal.Currency = shipment.Currency.ToString(); if (shipment.DeliveryAddress != null) { retVal.Addresses = new ObservableCollection<AddressEntity>(new AddressEntity[] { shipment.DeliveryAddress.ToDataModel() }); } if (shipment.Items != null) { retVal.Items = new ObservableCollection<ShipmentItemEntity>(shipment.Items.Select(x => x.ToDataModel(cartEntity, pkMap))); } if (shipment.TaxDetails != null) { retVal.TaxDetails = new ObservableCollection<TaxDetailEntity>(); retVal.TaxDetails.AddRange(shipment.TaxDetails.Select(x => x.ToDataModel())); } if (shipment.Discounts != null) { retVal.Discounts = new ObservableCollection<DiscountEntity>(); retVal.Discounts.AddRange(shipment.Discounts.Select(x => x.ToDataModel(pkMap))); } return retVal; }
public static ShipmentItemEntity ToDataModel(this ShipmentItem shipmentItem, ShoppingCartEntity cartEntity, PrimaryKeyResolvingMap pkMap) { if (shipmentItem == null) throw new ArgumentNullException("shipmentItem"); var retVal = new ShipmentItemEntity(); pkMap.AddPair(shipmentItem, retVal); retVal.InjectFrom(shipmentItem); //Try to find cart line item by shipment item if(!String.IsNullOrEmpty(shipmentItem.LineItemId)) { retVal.LineItem = cartEntity.Items.FirstOrDefault(x => x.Id == shipmentItem.LineItemId); } if(retVal.LineItem == null && shipmentItem.LineItem != null) { retVal.LineItem = cartEntity.Items.FirstOrDefault(x => x.Id == shipmentItem.LineItem.Id); } if (retVal.LineItem == null && shipmentItem.LineItem != null) { retVal.LineItem = cartEntity.Items.FirstOrDefault(x => x.ProductId == shipmentItem.LineItem.ProductId); } if(retVal.LineItem != null && !String.IsNullOrEmpty(retVal.LineItem.Id)) { retVal.LineItemId = retVal.LineItem.Id; retVal.LineItem = null; } return retVal; }
public static ShoppingCartEntity ToDataModel(this ShoppingCart cart) { if (cart == null) throw new ArgumentNullException("cart"); var retVal = new ShoppingCartEntity(); retVal.InjectFrom(cart); retVal.Currency = cart.Currency.ToString(); if (cart.Addresses != null) { retVal.Addresses = new ObservableCollection<AddressEntity>(cart.Addresses.Select(x => x.ToDataModel())); } if (cart.Items != null) { retVal.Items = new ObservableCollection<LineItemEntity>(cart.Items.Select(x => x.ToDataModel())); } if (cart.Shipments != null) { retVal.Shipments = new ObservableCollection<ShipmentEntity>(cart.Shipments.Select(x => x.ToDataModel())); } if (cart.Payments != null) { retVal.Payments = new ObservableCollection<PaymentEntity>(cart.Payments.Select(x => x.ToDataModel())); } if (cart.TaxDetails != null) { retVal.TaxDetails = new ObservableCollection<TaxDetailEntity>(); retVal.TaxDetails.AddRange(cart.TaxDetails.Select(x => x.ToDataModel())); } return retVal; }
/// <summary> /// Patch CatalogBase type /// </summary> /// <param name="source"></param> /// <param name="target"></param> public static void Patch(this ShoppingCartEntity source, ShoppingCartEntity target) { if (target == null) throw new ArgumentNullException("target"); var patchInjectionPolicy = new PatchInjection<ShoppingCartEntity>(x => x.Currency, x => x.Name, x=> x.ValidationType, x => x.CustomerId, x => x.CustomerName, x => x.IsAnonymous, x => x.IsRecuring, x => x.LanguageCode, x => x.Comment, x => x.OrganizationId, x => x.Total, x => x.SubTotal, x => x.ShippingTotal, x => x.HandlingTotal, x => x.DiscountTotal, x => x.TaxTotal, x => x.Coupon); target.InjectFrom(patchInjectionPolicy, source); if (string.IsNullOrEmpty(source.Coupon)) { target.Coupon = null; } if (!source.Items.IsNullCollection()) { source.Items.Patch(target.Items, (sourceItem, targetItem) => sourceItem.Patch(targetItem)); } if (!source.Payments.IsNullCollection()) { source.Payments.Patch(target.Payments, (sourcePayment, targetPayment) => sourcePayment.Patch(targetPayment)); } if (!source.Addresses.IsNullCollection()) { source.Addresses.Patch(target.Addresses, new AddressComparer(), (sourceAddress, targetAddress) => sourceAddress.Patch(targetAddress)); } if (!source.Shipments.IsNullCollection()) { source.Shipments.Patch(target.Shipments, (sourceShipment, targetShipment) => sourceShipment.Patch(targetShipment)); } if (!source.TaxDetails.IsNullCollection()) { var taxDetailComparer = AnonymousComparer.Create((TaxDetailEntity x) => x.Name); source.TaxDetails.Patch(target.TaxDetails, taxDetailComparer, (sourceTaxDetail, targetTaxDetail) => sourceTaxDetail.Patch(targetTaxDetail)); } if (!source.Discounts.IsNullCollection()) { source.Discounts.Patch(target.Discounts, new DiscountComparer(), (sourceDiscount, targetDiscount) => sourceDiscount.Patch(targetDiscount)); } }
public void Tst1() { var repository = new CartRepositoryImpl("VirtoCommerce", new AuditableInterceptor(), new EntityPrimaryKeyGeneratorInterceptor()); var cart = new dataModel.ShoppingCartEntity { StoreId = "ss", CustomerId = "ss", Currency = "ss", }; var shipment = new dataModel.ShipmentEntity { Currency = "sss", }; cart.Shipments.Add(shipment); repository.Add(cart); repository.UnitOfWork.Commit(); }
public void Tst1() { var repository = new CartRepositoryImpl("VirtoCommerce", new AuditableInterceptor(), new EntityPrimaryKeyGeneratorInterceptor()); var cart = new dataModel.ShoppingCartEntity { StoreId = "ss", CustomerId = "ss", Currency = "ss", }; var shipment = new dataModel.ShipmentEntity { Currency = "sss", }; cart.Shipments.Add(shipment); repository.Add(cart); repository.UnitOfWork.Commit(); }
public static ShoppingCartEntity ToDataModel(this ShoppingCart cart, PrimaryKeyResolvingMap pkMap) { if (cart == null) throw new ArgumentNullException("cart"); var retVal = new ShoppingCartEntity(); pkMap.AddPair(cart, retVal); retVal.InjectFrom(cart); retVal.Currency = cart.Currency; if (cart.Addresses != null) { retVal.Addresses = new ObservableCollection<AddressEntity>(cart.Addresses.Select(x => x.ToDataModel())); } if (cart.Items != null) { retVal.Items = new ObservableCollection<LineItemEntity>(cart.Items.Select(x => x.ToDataModel(pkMap))); } if (cart.Shipments != null) { retVal.Shipments = new ObservableCollection<ShipmentEntity>(cart.Shipments.Select(x => x.ToDataModel(retVal, pkMap))); } if (cart.Payments != null) { retVal.Payments = new ObservableCollection<PaymentEntity>(cart.Payments.Select(x => x.ToDataModel(pkMap))); } if (cart.TaxDetails != null) { retVal.TaxDetails = new ObservableCollection<TaxDetailEntity>(); retVal.TaxDetails.AddRange(cart.TaxDetails.Select(x => x.ToDataModel())); } if (cart.Discounts != null) { retVal.Discounts = new ObservableCollection<DiscountEntity>(); retVal.Discounts.AddRange(cart.Discounts.Select(x => x.ToDataModel(pkMap))); } return retVal; }
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 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)); } }
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)); } }