public override OrderOperation ToModel(OrderOperation operation) { var shipment = operation as Shipment; if (shipment == null) { throw new ArgumentException(@"operation argument must be of type Shipment", nameof(operation)); } if (!Addresses.IsNullOrEmpty()) { shipment.DeliveryAddress = Addresses.First().ToModel(AbstractTypeFactory <Address> .TryCreateInstance()); } shipment.Discounts = Discounts.Select(x => x.ToModel(AbstractTypeFactory <Discount> .TryCreateInstance())).ToList(); shipment.Items = Items.Select(x => x.ToModel(AbstractTypeFactory <ShipmentItem> .TryCreateInstance())).ToList(); shipment.InPayments = InPayments.Select(x => x.ToModel(AbstractTypeFactory <PaymentIn> .TryCreateInstance())).OfType <PaymentIn>().ToList(); shipment.Packages = Packages.Select(x => x.ToModel(AbstractTypeFactory <ShipmentPackage> .TryCreateInstance())).ToList(); shipment.TaxDetails = TaxDetails.Select(x => x.ToModel(AbstractTypeFactory <TaxDetail> .TryCreateInstance())).ToList(); base.ToModel(shipment); operation.Sum = shipment.TotalWithTax; return(shipment); }
public CustomerOrderEntity GetCustomerOrderById(string id, CustomerOrderResponseGroup responseGroup) { var query = CustomerOrders.Where(x => x.Id == id) .Include(x => x.Discounts) .Include(x => x.TaxDetails); if ((responseGroup & CustomerOrderResponseGroup.WithAddresses) == CustomerOrderResponseGroup.WithAddresses) { var addresses = Addresses.Where(x => x.CustomerOrderId == id).ToArray(); } if ((responseGroup & CustomerOrderResponseGroup.WithInPayments) == CustomerOrderResponseGroup.WithInPayments) { var inPayments = InPayments.Where(x => x.CustomerOrderId == id).ToArray(); var paymentsIds = inPayments.Select(x => x.Id).ToArray(); var paymentAddresses = Addresses.Where(x => paymentsIds.Contains(x.PaymentInId)).ToArray(); } if ((responseGroup & CustomerOrderResponseGroup.WithItems) == CustomerOrderResponseGroup.WithItems) { var lineItems = LineItems.Include(x => x.TaxDetails) .Include(x => x.Discounts) .Where(x => x.CustomerOrderId == id).ToArray(); } if ((responseGroup & CustomerOrderResponseGroup.WithShipments) == CustomerOrderResponseGroup.WithShipments) { var shipments = Shipments.Include(x => x.TaxDetails) .Include(x => x.Discounts) .Include(x => x.Items) .Include(x => x.Packages.Select(y => y.Items)) .Where(x => x.CustomerOrderId == id).ToArray(); var shipmentIds = shipments.Select(x => x.Id).ToArray(); var addresses = Addresses.Where(x => shipmentIds.Contains(x.ShipmentId)).ToArray(); } return(query.FirstOrDefault()); }
public override OrderOperation ToModel(OrderOperation operation) { var order = operation as CustomerOrder; if (order == null) { throw new ArgumentException(@"operation argument must be of type CustomerOrder", nameof(operation)); } order.CustomerId = CustomerId; order.CustomerName = CustomerName; order.StoreId = StoreId; order.StoreName = StoreName; order.OrganizationId = OrganizationId; order.OrganizationName = OrganizationName; order.EmployeeId = EmployeeId; order.EmployeeName = EmployeeName; order.DiscountAmount = DiscountAmount; order.Total = Total; order.SubTotal = SubTotal; order.SubTotalWithTax = SubTotalWithTax; order.ShippingTotal = ShippingTotal; order.ShippingTotalWithTax = ShippingTotalWithTax; order.PaymentTotal = PaymentTotal; order.PaymentTotalWithTax = PaymentTotalWithTax; order.FeeTotal = HandlingTotal; order.FeeTotalWithTax = HandlingTotalWithTax; order.DiscountTotal = DiscountTotal; order.DiscountTotalWithTax = DiscountTotalWithTax; order.DiscountAmount = DiscountAmount; order.TaxTotal = TaxTotal; order.IsPrototype = IsPrototype; order.SubscriptionNumber = SubscriptionNumber; order.SubscriptionId = SubscriptionId; order.LanguageCode = LanguageCode; order.TaxPercentRate = TaxPercentRate; order.Discounts = Discounts.Select(x => x.ToModel(AbstractTypeFactory <Discount> .TryCreateInstance())).ToList(); order.Items = Items.Select(x => x.ToModel(AbstractTypeFactory <LineItem> .TryCreateInstance())).ToList(); order.Addresses = Addresses.Select(x => x.ToModel(AbstractTypeFactory <Address> .TryCreateInstance())).ToList(); order.Shipments = Shipments.Select(x => x.ToModel(AbstractTypeFactory <Shipment> .TryCreateInstance())).OfType <Shipment>().ToList(); order.InPayments = InPayments.Select(x => x.ToModel(AbstractTypeFactory <PaymentIn> .TryCreateInstance())).OfType <PaymentIn>().ToList(); order.TaxDetails = TaxDetails.Select(x => x.ToModel(AbstractTypeFactory <TaxDetail> .TryCreateInstance())).ToList(); order.DynamicProperties = DynamicPropertyObjectValues.GroupBy(g => g.PropertyId).Select(x => { var property = AbstractTypeFactory <DynamicObjectProperty> .TryCreateInstance(); property.Id = x.Key; property.Name = x.FirstOrDefault()?.PropertyName; property.Values = x.Select(v => v.ToModel(AbstractTypeFactory <DynamicPropertyObjectValue> .TryCreateInstance())).ToArray(); return(property); }).ToArray(); base.ToModel(order); Sum = order.Total; return(order); }
public override OrderOperation ToModel(OrderOperation operation) { var shipment = operation as Shipment; if (shipment == null) { throw new ArgumentException(@"operation argument must be of type Shipment", nameof(operation)); } if (!Addresses.IsNullOrEmpty()) { shipment.DeliveryAddress = Addresses.First().ToModel(AbstractTypeFactory <Address> .TryCreateInstance()); } shipment.Id = Id; shipment.CreatedDate = CreatedDate; shipment.CreatedBy = CreatedBy; shipment.ModifiedDate = ModifiedDate; shipment.ModifiedBy = ModifiedBy; shipment.Price = Price; shipment.PriceWithTax = PriceWithTax; shipment.DiscountAmount = DiscountAmount; shipment.DiscountAmountWithTax = DiscountAmountWithTax; shipment.FulfillmentCenterId = FulfillmentCenterId; shipment.FulfillmentCenterName = FulfillmentCenterName; shipment.OrganizationId = OrganizationId; shipment.OrganizationName = OrganizationName; shipment.EmployeeId = EmployeeId; shipment.EmployeeName = EmployeeName; shipment.ShipmentMethodCode = ShipmentMethodCode; shipment.ShipmentMethodOption = ShipmentMethodOption; shipment.Height = Height; shipment.Length = Length; shipment.Weight = Weight; shipment.Height = Height; shipment.Width = Width; shipment.MeasureUnit = MeasureUnit; shipment.WeightUnit = WeightUnit; shipment.Length = Length; shipment.TaxType = TaxType; shipment.TaxPercentRate = TaxPercentRate; shipment.TaxTotal = TaxTotal; shipment.Total = Total; shipment.TotalWithTax = TotalWithTax; shipment.Discounts = Discounts.Select(x => x.ToModel(AbstractTypeFactory <Discount> .TryCreateInstance())).ToList(); shipment.Items = Items.Select(x => x.ToModel(AbstractTypeFactory <ShipmentItem> .TryCreateInstance())).ToList(); shipment.InPayments = InPayments.Select(x => x.ToModel(AbstractTypeFactory <PaymentIn> .TryCreateInstance())).OfType <PaymentIn>().ToList(); shipment.Packages = Packages.Select(x => x.ToModel(AbstractTypeFactory <ShipmentPackage> .TryCreateInstance())).ToList(); shipment.TaxDetails = TaxDetails.Select(x => x.ToModel(AbstractTypeFactory <TaxDetail> .TryCreateInstance())).ToList(); base.ToModel(shipment); operation.Sum = shipment.TotalWithTax; return(shipment); }
public override object Clone() { var result = base.Clone() as CustomerOrder; result.TaxDetails = TaxDetails?.Select(x => x.Clone()).OfType <TaxDetail>().ToList(); result.Addresses = Addresses?.Select(x => x.Clone()).OfType <Address>().ToList(); result.InPayments = InPayments?.Select(x => x.Clone()).OfType <PaymentIn>().ToList(); result.Items = Items?.Select(x => x.Clone()).OfType <LineItem>().ToList(); result.Shipments = Shipments?.Select(x => x.Clone()).OfType <Shipment>().ToList(); result.Discounts = Discounts?.Select(x => x.Clone()).OfType <Discount>().ToList(); return(result); }
public override object Clone() { var result = base.Clone() as Shipment; result.DeliveryAddress = DeliveryAddress?.Clone() as Address; result.ShippingMethod = ShippingMethod?.Clone() as ShippingMethod; result.CustomerOrder = CustomerOrder?.Clone() as CustomerOrder; result.Items = Items?.Select(x => x.Clone()).OfType <ShipmentItem>().ToList(); result.Packages = Packages?.Select(x => x.Clone()).OfType <ShipmentPackage>().ToList(); result.InPayments = InPayments?.Select(x => x.Clone()).OfType <PaymentIn>().ToList(); result.Discounts = Discounts?.Select(x => x.Clone()).OfType <Discount>().ToList(); result.TaxDetails = TaxDetails?.Select(x => x.Clone()).OfType <TaxDetail>().ToList(); return(result); }
public override OrderOperation ToModel(OrderOperation operation) { var order = operation as CustomerOrder; if (order == null) { throw new ArgumentException(@"operation argument must be of type CustomerOrder", nameof(operation)); } order.Discounts = Discounts.Select(x => x.ToModel(AbstractTypeFactory <Discount> .TryCreateInstance())).ToList(); order.Items = Items.Select(x => x.ToModel(AbstractTypeFactory <LineItem> .TryCreateInstance())).ToList(); order.Addresses = Addresses.Select(x => x.ToModel(AbstractTypeFactory <Address> .TryCreateInstance())).ToList(); order.Shipments = Shipments.Select(x => x.ToModel(AbstractTypeFactory <Shipment> .TryCreateInstance())).OfType <Shipment>().ToList(); order.InPayments = InPayments.Select(x => x.ToModel(AbstractTypeFactory <PaymentIn> .TryCreateInstance())).OfType <PaymentIn>().ToList(); order.TaxDetails = TaxDetails.Select(x => x.ToModel(AbstractTypeFactory <TaxDetail> .TryCreateInstance())).ToList(); base.ToModel(order); Sum = order.Total; return(order); }
public virtual CustomerOrderEntity[] GetCustomerOrdersByIds(string[] ids, CustomerOrderResponseGroup responseGroup) { var query = CustomerOrders.Where(x => ids.Contains(x.Id)) .Include(x => x.Discounts) .Include(x => x.TaxDetails); if ((responseGroup & CustomerOrderResponseGroup.WithAddresses) == CustomerOrderResponseGroup.WithAddresses) { var addresses = Addresses.Where(x => ids.Contains(x.CustomerOrderId)).ToArray(); } if ((responseGroup & CustomerOrderResponseGroup.WithInPayments) == CustomerOrderResponseGroup.WithInPayments) { var inPayments = InPayments.Include(x => x.TaxDetails) .Include(x => x.Discounts) .Where(x => ids.Contains(x.CustomerOrderId)).ToArray(); var paymentsIds = inPayments.Select(x => x.Id).ToArray(); var paymentAddresses = Addresses.Where(x => paymentsIds.Contains(x.PaymentInId)).ToArray(); var transactions = Transactions.Where(x => paymentsIds.Contains(x.PaymentInId)).ToArray(); } if ((responseGroup & CustomerOrderResponseGroup.WithItems) == CustomerOrderResponseGroup.WithItems) { var lineItems = LineItems.Include(x => x.TaxDetails) .Include(x => x.Discounts) .Where(x => ids.Contains(x.CustomerOrderId)).ToArray(); } if ((responseGroup & CustomerOrderResponseGroup.WithShipments) == CustomerOrderResponseGroup.WithShipments) { var shipments = Shipments.Include(x => x.TaxDetails) .Include(x => x.Discounts) .Include(x => x.Items) .Include(x => x.Packages.Select(y => y.Items)) .Where(x => ids.Contains(x.CustomerOrderId)).ToArray(); var shipmentIds = shipments.Select(x => x.Id).ToArray(); var addresses = Addresses.Where(x => shipmentIds.Contains(x.ShipmentId)).ToArray(); } return(query.ToArray()); }
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 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); }
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.DiscountAmount = DiscountAmount; 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.IsPrototype = IsPrototype; target.SubscriptionNumber = SubscriptionNumber; target.SubscriptionId = SubscriptionId; target.LanguageCode = LanguageCode; target.TaxPercentRate = TaxPercentRate; if (!Addresses.IsNullCollection()) { Addresses.Patch(target.Addresses, (sourceItem, targetItem) => sourceItem.Patch(targetItem)); } if (!Shipments.IsNullCollection()) { 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)); } base.Patch(operation); }