示例#1
0
        public virtual IHttpActionResult PostCart([FromBody] OrderGroup orderGroup)
        {
            Logger.LogPost("PostCart", Request);

            try
            {
                if (string.IsNullOrEmpty(orderGroup.Name))
                {
                    throw new ArgumentNullException(nameof(orderGroup.Name));
                }

                if (orderGroup.CustomerId == Guid.Empty)
                {
                    throw new ArgumentNullException(nameof(orderGroup.CustomerId));
                }

                var cart = _orderRepository.Create <Cart>(orderGroup.CustomerId, orderGroup.Name);

                cart = orderGroup.ConvertToCart(cart);

                _promotionEngine.Run(cart);
                cart.AcceptChanges();

                return(Ok(cart));
            }
            catch (Exception exception)
            {
                Logger.Error(exception.Message, exception);
                return(InternalServerError(exception));
            }
        }
 private static void MapOrderNotes(
     OrderGroup orderGroupDto, Mediachase.Commerce.Orders.OrderGroup orderGroup)
 {
     foreach (var orderNote in orderGroupDto.OrderNotes)
     {
         var note = orderGroup.OrderNotes
                    .FirstOrDefault(x => x.OrderNoteId == orderNote.OrderNoteId)
                    ?? orderGroup.OrderNotes.AddNew();
         orderNote.ConvertToOrderNote(note);
     }
 }
 private static void MapOrderAddresses(
     OrderGroup orderGroupDto, Mediachase.Commerce.Orders.OrderGroup orderGroup)
 {
     foreach (var orderAddress in orderGroupDto.OrderAddresses)
     {
         var address = orderGroup.OrderAddresses
                       .FirstOrDefault(x => x.OrderGroupAddressId == orderAddress.OrderGroupAddressId)
                       ?? orderGroup.OrderAddresses.AddNew();
         orderAddress.ConvertToOrderAddress(address);
     }
 }
        private static void MapOrderForms(
            OrderGroup orderGroupDto, Mediachase.Commerce.Orders.OrderGroup orderGroup)
        {
            if (orderGroupDto.OrderForms.Length == 0)
            {
                return;
            }
            var orderForm = orderGroupDto.OrderForms.First();
            var form      = orderGroup.OrderForms.First();

            orderForm.ConvertToOrderForm(form);
        }
        public static PaymentPlan ConvertToPaymentPlan(this OrderGroup orderGroup, PaymentPlan paymentPlan)
        {
            if (!string.IsNullOrEmpty(orderGroup.AddressId))
            {
                paymentPlan.AddressId = orderGroup.AddressId;
            }

            if (orderGroup.AffiliateId != Guid.Empty)
            {
                paymentPlan.AffiliateId = orderGroup.AffiliateId;
            }

            if (!string.IsNullOrEmpty(orderGroup.BillingCurrency))
            {
                paymentPlan.BillingCurrency = orderGroup.BillingCurrency;
            }

            if (!string.IsNullOrEmpty(orderGroup.CustomerName))
            {
                paymentPlan.CustomerName = orderGroup.CustomerName;
            }

            if (orderGroup.HandlingTotal >= 0)
            {
                paymentPlan.HandlingTotal = orderGroup.HandlingTotal;
            }

            if (orderGroup.InstanceId != Guid.Empty)
            {
                paymentPlan.InstanceId = orderGroup.InstanceId;
            }

            if (orderGroup.MarketId != null)
            {
                paymentPlan.MarketId = orderGroup.MarketId;
            }

            if (!string.IsNullOrEmpty(orderGroup.Owner))
            {
                paymentPlan.Owner = orderGroup.Owner;
            }

            if (!string.IsNullOrEmpty(orderGroup.OwnerOrg))
            {
                paymentPlan.OwnerOrg = orderGroup.OwnerOrg;
            }

            if (!string.IsNullOrEmpty(orderGroup.ProviderId))
            {
                paymentPlan.ProviderId = orderGroup.ProviderId;
            }

            if (orderGroup.ShippingTotal >= 0)
            {
                paymentPlan.ShippingTotal = orderGroup.ShippingTotal;
            }

            if (!string.IsNullOrEmpty(orderGroup.Status))
            {
                paymentPlan.Status = orderGroup.Status;
            }

            if (orderGroup.SubTotal >= 0)
            {
                paymentPlan.SubTotal = orderGroup.SubTotal;
            }

            if (orderGroup.TaxTotal >= 0)
            {
                paymentPlan.TaxTotal = orderGroup.TaxTotal;
            }

            if (orderGroup.Total >= 0)
            {
                paymentPlan.Total = orderGroup.Total;
            }

            orderGroup.MapPropertiesToModel(paymentPlan);
            MapOrderAddresses(orderGroup, paymentPlan);
            MapOrderNotes(orderGroup, paymentPlan);
            MapOrderForms(orderGroup, paymentPlan);

            return(paymentPlan);
        }
        public static Cart ConvertToCart(this OrderGroup orderGroup, Cart cart)
        {
            if (!string.IsNullOrEmpty(orderGroup.AddressId))
            {
                cart.AddressId = orderGroup.AddressId;
            }

            if (orderGroup.AffiliateId != Guid.Empty)
            {
                cart.AffiliateId = orderGroup.AffiliateId;
            }

            if (!string.IsNullOrEmpty(orderGroup.BillingCurrency))
            {
                cart.BillingCurrency = orderGroup.BillingCurrency;
            }

            if (!string.IsNullOrEmpty(orderGroup.CustomerName))
            {
                cart.CustomerName = orderGroup.CustomerName;
            }

            if (orderGroup.HandlingTotal >= 0)
            {
                cart.HandlingTotal = orderGroup.HandlingTotal;
            }

            if (orderGroup.InstanceId != Guid.Empty)
            {
                cart.InstanceId = orderGroup.InstanceId;
            }

            if (orderGroup.MarketId != null)
            {
                cart.MarketId = orderGroup.MarketId;
            }

            if (!string.IsNullOrEmpty(orderGroup.Owner))
            {
                cart.Owner = orderGroup.Owner;
            }

            if (!string.IsNullOrEmpty(orderGroup.OwnerOrg))
            {
                cart.OwnerOrg = orderGroup.OwnerOrg;
            }

            if (!string.IsNullOrEmpty(orderGroup.ProviderId))
            {
                cart.ProviderId = orderGroup.ProviderId;
            }

            if (orderGroup.ShippingTotal >= 0)
            {
                cart.ShippingTotal = orderGroup.ShippingTotal;
            }

            if (!string.IsNullOrEmpty(orderGroup.Status))
            {
                cart.Status = orderGroup.Status;
            }

            if (orderGroup.SubTotal >= 0)
            {
                cart.SubTotal = orderGroup.SubTotal;
            }

            if (orderGroup.TaxTotal >= 0)
            {
                cart.TaxTotal = orderGroup.TaxTotal;
            }

            if (orderGroup.Total >= 0)
            {
                cart.Total = orderGroup.Total;
            }

            orderGroup.MapPropertiesToModel(cart);
            MapOrderAddresses(orderGroup, cart);
            MapOrderNotes(orderGroup, cart);
            MapOrderForms(orderGroup, cart);

            return(cart);
        }