/// <summary>
 /// 构造函数,从数据库读取订单信息
 /// </summary>
 public OrderPageViewModel()
 {
     OrderList = new OrderForm<Order>();
     LoadMenuData();
     SelectMenuCommand = new DelegateCommand(new Action<object>(SelectMenuProc));
     SumbitCommand=new DelegateCommand(new Action<object>(PostOrdersProc));
 }
 private static void DeleteInvalidItem(OrderForm[] orderForms, LineItem lineItem)
 {
     foreach (var form in orderForms)
     {
         form.RemoveLineItemFromShipments(lineItem);
     }
     lineItem.Delete();
 }
 /// <summary>
 /// Updates the totals for an order form.
 /// </summary>
 /// <param name="orderForm">The order form</param>
 /// <param name="totals">The model containing calculated totals for the order form.</param>
 protected virtual void UpdateOrderFormTotals(OrderForm orderForm, OrderFormTotals totals)
 {
     orderForm.HandlingTotal = totals.HandlingTotal.Amount;
     orderForm.ShippingTotal = totals.ShippingTotal.Amount;
     orderForm.SubTotal = totals.SubTotal.Amount;
     orderForm.TaxTotal = totals.TaxTotal.Amount;
     orderForm.Total = totals.Total.Amount;
 }
 public IActionResult ReactSample()
 {
     OrderForm OrderForm = new OrderForm();
     OrderForm.ShoppingCounter = "1";
     OrderForm.Products = new List<ProductData>();
     OrderForm.Products.Add(new ProductData(1, "Bottle"));
     OrderForm.Products.Add(new ProductData(1, "Book"));
     return View(OrderForm);
 }
 private decimal GetCustomOrderDiscountAmount(OrderForm form)
 {
     decimal retVal = 0m;
     foreach (OrderFormDiscount orderFormDiscount in form.Discounts)
     {
         if (orderFormDiscount.DiscountName.StartsWith("@"))
         {
             retVal += orderFormDiscount.DiscountValue;
         }
     }
     return retVal;
 }
        private void SplitForm(OrderForm form)
        {
            int index = 0;
            foreach (LineItem item in form.LineItems)
            {
                Shipment itemShipment = null;
                string key = index.ToString();

                // Find appropriate shipment for item
                foreach (Shipment shipment in form.Shipments)
                {
                    if ((string.IsNullOrEmpty(shipment.ShippingAddressId) && string.IsNullOrEmpty(item.ShippingAddressId)) ||
                        OrderGroup.OrderAddresses.Cast<OrderAddress>().Any(x => x.Name.Equals(shipment.ShippingAddressId)))
                    {
                        itemShipment = shipment;
                    }
                    else
                    {
                        if (shipment.LineItemIndexes.Contains(key))
                            shipment.RemoveLineItemIndex(Convert.ToInt32(key));
                    }
                }

                // did we find any shipment?
                if (itemShipment == null)
                {
                    itemShipment = form.Shipments.AddNew();
                    itemShipment.ShippingAddressId = item.ShippingAddressId;
                    itemShipment.ShippingMethodId = item.ShippingMethodId;
                    itemShipment.ShippingMethodName = item.ShippingMethodName;
                }

                // As long as this is only used in conjunction with GetFulfillmentCenterActivity, this should be OK...
                if (String.IsNullOrEmpty(itemShipment.WarehouseCode))
                {
                    itemShipment.WarehouseCode = item.WarehouseCode;
                }

                // Add item to the shipment
                //if (item.LineItemId == 0)
                //    throw new ArgumentNullException("LineItemId = 0");

                if (itemShipment.LineItemIndexes.Contains(key))
                    itemShipment.RemoveLineItemIndex(key);

                //if (!itemShipment.LineItemIds.Contains(key))
                itemShipment.AddLineItemIndex(index, item.Quantity);

                index++;
            }
        }
Example #7
0
            public void Example()
            {
                Mapper.CreateMap<OrderForm, ICreateOrderMessage>();

                Mapper.AssertConfigurationIsValid();

                var order = new OrderForm
                    {
                        Customer = new Customer {Name = "Bob Smith"}
                    };

                var message = Mapper.Map<OrderForm, ICreateOrderMessage>(order);

                message.CustomerName.ShouldEqual("Bob Smith");
            }
        /// <summary>
        /// This method is called before the order is completed. This method should check all the parameters
        /// and validate the credit card or other parameters accepted.
        /// </summary>
        /// <param name="orderForm"></param>
        /// <returns>bool</returns>
        public Payment PreProcess(OrderForm orderForm)
        {
            var payment = GetCreditCardPayment();
            if (!ValidateData() || payment == null)
            {
                // Intend to throw exception to stop processing unnecessary later steps (the sample site catch this exception to handle)
                throw new ArgumentException("Invalid credit card information.");
            }

            if (orderForm == null)
            {
                throw new ArgumentNullException("orderForm");
            }

            payment.BillingAddressId = orderForm.BillingAddressId;
            return payment;
        }
        public bool PostProcess(OrderForm form)
        {
            if (form == null)
            {
                throw new ArgumentNullException("form");
            }

            var payment = form.Payments.ToArray().FirstOrDefault(x => x.PaymentMethodId == this.PaymentMethodId);
            if (payment == null)
            { 
                return false;
            }

            payment.Status = PaymentStatus.Processed.ToString();
            payment.AcceptChanges();

            return true;
        }
        public Mediachase.Commerce.Orders.Payment PreProcess(OrderForm form)
        {
            if (form == null)
            {
                throw new ArgumentNullException("form");
            }

            var payment = new OtherPayment
            {
                PaymentMethodId = PaymentMethodId,
                PaymentMethodName = "CashOnDelivery",
                OrderFormId = form.OrderFormId,
                OrderGroupId = form.OrderGroupId,
                Amount = form.Total,
                Status = PaymentStatus.Pending.ToString(),
                TransactionType = TransactionType.Authorization.ToString()
            };

            return payment;
        }
 private OrderFormModel MapOrderForm(OrderForm orderForm)
 {
     return new OrderFormModel()
     {
         Discounts = MapDiscounts(orderForm.Discounts),
         LineItems = orderForm.LineItems.Select(MapToModel),
         Payments = orderForm.Payments.OrEmpty().Select(MapToModel).ToArray(),
         Shipments = orderForm.Shipments.OrEmpty().Select(MapToModel).ToArray()
     };
 }
Example #12
0
        private void PopulateTestOrder()
        {
            if (MockOrderList == null)
            {
                MockOrderList          = new List <OrderModel.Order>();
                MockPaymentList        = new List <Payment>();
                MockShippingOptionList = new List <ShippingOption>();
                MockPaymentGatewayList = new List <PaymentGateway>();
                MockPaymentMethodList  = new List <PaymentMethod>();
                MockCountryList        = new List <Country>();

                MockOrderList.Add(new OrderModel.Order {
                    BillingCurrency = "USD", StoreId = "UK Store", OrderGroupId = "1", TrackingNumber = "PO32313", Status = "OnHold", Total = 123.43m, CustomerId = "1"
                });
                MockOrderList.Add(new OrderModel.Order {
                    BillingCurrency = "USD", StoreId = "UK Store", OrderGroupId = "2", TrackingNumber = "PO62316", Status = "Completed", Total = 444.12m, CustomerId = "2"
                });
                MockOrderList.Add(new OrderModel.Order {
                    BillingCurrency = "USD", StoreId = "UK Store", OrderGroupId = "3", TrackingNumber = "PO75423", Status = "OnHold", Total = 765.32m, CustomerId = "3"
                });
                MockOrderList.Add(new OrderModel.Order {
                    BillingCurrency = "USD", StoreId = "UK Store", OrderGroupId = "4", TrackingNumber = "PO98743", Status = "Completed", Total = 775.22m, CustomerId = "4"
                });
                MockOrderList.Add(new OrderModel.Order {
                    BillingCurrency = "USD", StoreId = "UK Store", OrderGroupId = "5", TrackingNumber = "PO36572", Status = "InProgress", Total = 66.43m, CustomerId = "5"
                });
                MockOrderList.Add(new OrderModel.Order {
                    BillingCurrency = "USD", StoreId = "UK Store", OrderGroupId = "6", TrackingNumber = "PO65432", Status = "InProgress", Total = 632.12m, CustomerId = "6"
                });
                MockOrderList.Add(new OrderModel.Order {
                    BillingCurrency = "USD", StoreId = "UK Store", OrderGroupId = "7", TrackingNumber = "PO97898", Status = "OnHold", Total = 642.21m, CustomerId = "7"
                });

                MockOrderList.Add(new OrderModel.Order {
                    BillingCurrency = "USD", StoreId = "US Store", OrderGroupId = "10", TrackingNumber = "POS2313", Total = 123.43m, CustomerId = "11"
                });
                MockOrderList.Add(new OrderModel.Order {
                    BillingCurrency = "USD", StoreId = "US Store", OrderGroupId = "20", TrackingNumber = "POS2316", Status = "Completed", Total = 444.12m, CustomerId = "12"
                });
                MockOrderList.Add(new OrderModel.Order {
                    BillingCurrency = "USD", StoreId = "US Store", OrderGroupId = "30", TrackingNumber = "POS5423", Total = 765.32m, CustomerId = "13"
                });
                MockOrderList.Add(new OrderModel.Order {
                    BillingCurrency = "USD", StoreId = "US Store", OrderGroupId = "40", TrackingNumber = "POS8743", Status = "Completed", Total = 775.22m, CustomerId = "14"
                });
                MockOrderList.Add(new OrderModel.Order {
                    BillingCurrency = "USD", StoreId = "US Store", OrderGroupId = "50", TrackingNumber = "POS6572", Status = "InProgress", Total = 66.43m, CustomerId = "15"
                });
                MockOrderList.Add(new OrderModel.Order {
                    BillingCurrency = "USD", StoreId = "US Store", OrderGroupId = "60", TrackingNumber = "POS5432", Status = "InProgress", Total = 632.12m, CustomerId = "16"
                });
                MockOrderList.Add(new OrderModel.Order {
                    BillingCurrency = "USD", StoreId = "US Store", OrderGroupId = "70", TrackingNumber = "POS7898", Total = 642.21m, CustomerId = "17"
                });

                MockOrderList.Add(new OrderModel.Order {
                    BillingCurrency = "USD", StoreId = "US Store", OrderGroupId = "11", TrackingNumber = "PO62313", Total = 123.43m, CustomerId = "11"
                });
                MockOrderList.Add(new OrderModel.Order {
                    BillingCurrency = "USD", StoreId = "US Store", OrderGroupId = "12", TrackingNumber = "PO92316", Status = "Completed", Total = 444.12m, CustomerId = "12"
                });
                MockOrderList.Add(new OrderModel.Order {
                    BillingCurrency = "USD", StoreId = "US Store", OrderGroupId = "13", TrackingNumber = "PO25423", Total = 765.32m, CustomerId = "13"
                });
                MockOrderList.Add(new OrderModel.Order {
                    BillingCurrency = "USD", StoreId = "US Store", OrderGroupId = "14", TrackingNumber = "PO98743", Status = "Completed", Total = 775.22m, CustomerId = "14"
                });
                MockOrderList.Add(new OrderModel.Order {
                    BillingCurrency = "USD", StoreId = "US Store", OrderGroupId = "15", TrackingNumber = "PO66572", Total = 66.43m, CustomerId = "15"
                });
                MockOrderList.Add(new OrderModel.Order {
                    BillingCurrency = "USD", StoreId = "US Store", OrderGroupId = "16", TrackingNumber = "PO35432", Total = 632.12m, CustomerId = "16"
                });
                MockOrderList.Add(new OrderModel.Order {
                    BillingCurrency = "USD", StoreId = "US Store", OrderGroupId = "17", TrackingNumber = "PO07898", Total = 642.21m, CustomerId = "17"
                });

                MockOrderList.Add(new OrderModel.Order {
                    BillingCurrency = "USD", StoreId = "UK Store", OrderGroupId = "11", TrackingNumber = "PSS2313", Total = 123.43m, CustomerId = "11"
                });
                MockOrderList.Add(new OrderModel.Order {
                    BillingCurrency = "USD", StoreId = "UK Store", OrderGroupId = "21", TrackingNumber = "PSS2316", Status = "Completed", Total = 444.12m, CustomerId = "12"
                });
                MockOrderList.Add(new OrderModel.Order {
                    BillingCurrency = "USD", StoreId = "UK Store", OrderGroupId = "31", TrackingNumber = "PSS5423", Total = 765.32m, CustomerId = "13"
                });
                MockOrderList.Add(new OrderModel.Order {
                    BillingCurrency = "USD", StoreId = "UK Store", OrderGroupId = "41", TrackingNumber = "PSS8743", Status = "Completed", Total = 775.22m, CustomerId = "14"
                });
                MockOrderList.Add(new OrderModel.Order {
                    BillingCurrency = "USD", StoreId = "UK Store", OrderGroupId = "51", TrackingNumber = "PSS6572", Total = 66.43m, CustomerId = "15"
                });
                MockOrderList.Add(new OrderModel.Order {
                    BillingCurrency = "USD", StoreId = "UK Store", OrderGroupId = "61", TrackingNumber = "PSS5432", Total = 632.12m, CustomerId = "16"
                });
                MockOrderList.Add(new OrderModel.Order {
                    BillingCurrency = "USD", StoreId = "UK Store", OrderGroupId = "71", TrackingNumber = "PSS7898", Total = 642.21m, CustomerId = "17"
                });
                MockOrderList.Add(new OrderModel.Order {
                    BillingCurrency = "USD", StoreId = "UK Store", OrderGroupId = "21", TrackingNumber = "PS62313", Total = 123.43m, CustomerId = "11"
                });
                MockOrderList.Add(new OrderModel.Order {
                    BillingCurrency = "USD", StoreId = "UK Store", OrderGroupId = "22", TrackingNumber = "PS92316", Status = "Completed", Total = 444.12m, CustomerId = "12"
                });
                MockOrderList.Add(new OrderModel.Order {
                    BillingCurrency = "USD", StoreId = "UK Store", OrderGroupId = "23", TrackingNumber = "PS25423", Total = 765.32m, CustomerId = "13"
                });
                MockOrderList.Add(new OrderModel.Order {
                    BillingCurrency = "USD", StoreId = "UK Store", OrderGroupId = "24", TrackingNumber = "PS98743", Status = "Completed", Total = 775.22m, CustomerId = "14"
                });
                MockOrderList.Add(new OrderModel.Order {
                    BillingCurrency = "USD", StoreId = "UK Store", OrderGroupId = "25", TrackingNumber = "PS66572", Total = 66.43m, CustomerId = "15"
                });
                MockOrderList.Add(new OrderModel.Order {
                    BillingCurrency = "USD", StoreId = "UK Store", OrderGroupId = "26", TrackingNumber = "PS35432", Status = "Completed", Total = 632.12m, CustomerId = "16"
                });
                MockOrderList.Add(new OrderModel.Order {
                    BillingCurrency = "USD", StoreId = "UK Store", OrderGroupId = "27", TrackingNumber = "PS07898", Total = 642.21m, CustomerId = "17"
                });

                MockOrderList.Add(new OrderModel.Order {
                    BillingCurrency = "USD", StoreId = "UK Store", OrderGroupId = "12", TrackingNumber = "PSO2313", Total = 123.43m, CustomerId = "11"
                });
                MockOrderList.Add(new OrderModel.Order {
                    BillingCurrency = "USD", StoreId = "UK Store", OrderGroupId = "22", TrackingNumber = "PSO2316", Status = "Completed", Total = 444.12m, CustomerId = "12"
                });
                MockOrderList.Add(new OrderModel.Order {
                    BillingCurrency = "USD", StoreId = "UK Store", OrderGroupId = "32", TrackingNumber = "PSO5423", Total = 765.32m, CustomerId = "13"
                });
                MockOrderList.Add(new OrderModel.Order {
                    BillingCurrency = "USD", StoreId = "UK Store", OrderGroupId = "42", TrackingNumber = "PSO8743", Status = "Completed", Total = 775.22m, CustomerId = "14"
                });
                MockOrderList.Add(new OrderModel.Order {
                    BillingCurrency = "USD", StoreId = "UK Store", OrderGroupId = "52", TrackingNumber = "PSO6572", Total = 66.43m, CustomerId = "15"
                });
                MockOrderList.Add(new OrderModel.Order {
                    BillingCurrency = "USD", StoreId = "UK Store", OrderGroupId = "62", TrackingNumber = "PSO5432", Status = "AwaitingExchange", Total = 632.12m, CustomerId = "16"
                });
                MockOrderList.Add(new OrderModel.Order {
                    BillingCurrency = "USD", StoreId = "UK Store", OrderGroupId = "72", TrackingNumber = "PSO7898", Total = 642.21m, CustomerId = "17"
                });
                MockOrderList.Add(new OrderModel.Order {
                    BillingCurrency = "USD", StoreId = "UK Store", OrderGroupId = "32", TrackingNumber = "PSO2313", Total = 123.43m, CustomerId = "11"
                });
                MockOrderList.Add(new OrderModel.Order {
                    BillingCurrency = "USD", StoreId = "UK Store", OrderGroupId = "32", TrackingNumber = "PSO2316", Status = "Completed", Total = 444.12m, CustomerId = "12"
                });
                MockOrderList.Add(new OrderModel.Order {
                    BillingCurrency = "USD", StoreId = "UK Store", OrderGroupId = "33", TrackingNumber = "PSO5423", Total = 765.32m, CustomerId = "13"
                });
                MockOrderList.Add(new OrderModel.Order {
                    BillingCurrency = "USD", StoreId = "UK Store", OrderGroupId = "34", TrackingNumber = "PSO8743", Status = "Completed", Total = 775.22m, CustomerId = "14"
                });
                MockOrderList.Add(new OrderModel.Order {
                    BillingCurrency = "USD", StoreId = "UK Store", OrderGroupId = "35", TrackingNumber = "PSO6572", Total = 66.43m, CustomerId = "15"
                });
                MockOrderList.Add(new OrderModel.Order {
                    BillingCurrency = "USD", StoreId = "UK Store", OrderGroupId = "36", TrackingNumber = "PSO5432", Status = "AwaitingExchange", Total = 632.12m, CustomerId = "16"
                });
                MockOrderList.Add(new OrderModel.Order {
                    BillingCurrency = "USD", StoreId = "UK Store", OrderGroupId = "37", TrackingNumber = "PSO7898", Total = 642.21m, CustomerId = "17"
                });

                foreach (var order in MockOrderList)
                {
                    var payments = new Payment[] {
                        new CreditCardPayment()
                        {
                            PaymentType = PaymentType.CreditCard.GetHashCode(), PaymentMethodName = "MasterCard", ValidationCode = "RE21321-21", Amount = 32.53m, Status = "Processing", TransactionType = TransactionType.Credit.ToString()
                        },
                        new CashCardPayment()
                        {
                            PaymentType = PaymentType.CashCard.GetHashCode(), PaymentMethodName = "Visa", ValidationCode = "RE6211-44", Amount = 55.73m, Status = "Processing", TransactionType = TransactionType.Credit.ToString()
                        },
                        new InvoicePayment()
                        {
                            PaymentType = PaymentType.Invoice.GetHashCode(), PaymentMethodName = "Bank transaction", ValidationCode = "BE3-21", Amount = 774.53m, Status = "Confirmed", TransactionType = TransactionType.Authorization.ToString()
                        }
                    };
                    var orderAddresses = new OrderAddress[] {
                        new OrderAddress()
                        {
                            OrderAddressId = "1", City = "New Yourk", CountryCode = "us", CountryName = "USA", DaytimePhoneNumber = "+7 (906) 2121-321", Email = "*****@*****.**", Line1 = "str. 113", Line2 = "bld. 21", PostalCode = "323232", StateProvince = "WC"
                        },
                        new OrderAddress()
                        {
                            OrderAddressId = "2", City = "Los Angeles", CountryCode = "us", CountryName = "USA", DaytimePhoneNumber = "+7 (906) 4444-444", Email = "*****@*****.**", Line1 = "av. 32", Line2 = "bld. 1", PostalCode = "432142", StateProvince = "LA"
                        },
                        new OrderAddress()
                        {
                            OrderAddressId = "3", City = "Yourk", CountryCode = "us", CountryName = "USA", DaytimePhoneNumber = "+7 (906) 2121-321", Email = "*****@*****.**", Line1 = "str. 113", Line2 = "Pas Juozapa", PostalCode = "12100"
                        },
                        new OrderAddress()
                        {
                            OrderAddressId = "4", City = "Vilnius", CountryCode = "lt", CountryName = "Lithuania", DaytimePhoneNumber = "+370 5 2744-444", Line1 = "Laisves pr. 125", PostalCode = "12100"
                        },
                        new OrderAddress()
                        {
                            OrderAddressId = "5", City = "Yourk", CountryCode = "us", CountryName = "USA", DaytimePhoneNumber = "+7 (906) 2121-321", Email = "*****@*****.**", Line1 = "str. 113", Line2 = "Pas Juozapa", PostalCode = "12100"
                        },
                        new OrderAddress()
                        {
                            OrderAddressId = "6", City = "Vilnius", CountryCode = "lt", CountryName = "Lithuania", DaytimePhoneNumber = "+370 5 2744-444", Line1 = "Laisves pr. 125", PostalCode = "54821"
                        }
                    };

                    var lineItems = new LineItem[] {
                        new LineItem()
                        {
                            LineItemId = "1", DisplayName = "Chair black", Description = "some chair description", Quantity = 3, ListPrice = 32.43m, CatalogItemCode = "x-200"
                        },
                        new LineItem()
                        {
                            LineItemId = "2", DisplayName = "Coca-Cola", Description = "some coca description", Quantity = 4, ListPrice = 3.99m, CatalogItemCode = "x-201"
                        },
                        new LineItem()
                        {
                            LineItemId = "3", DisplayName = "Fujifilm 121MN", Description = "some fuji description", Quantity = 6, ListPrice = 89.37m, CatalogItemCode = "x-202"
                        },
                        new LineItem()
                        {
                            LineItemId = "4", DisplayName = "Canon M32-Z", Description = "some Canon description", Quantity = 9, ListPrice = 902.94m, CatalogItemCode = "x-203"
                        },
                        new LineItem()
                        {
                            LineItemId = "5", DisplayName = "Sony Qybershot", Description = "some Sony description", Quantity = 1, ListPrice = 320.49m, CatalogItemCode = "x-204"
                        },
                        new LineItem()
                        {
                            LineItemId = "6", DisplayName = "Minolta 121-43s", Description = "some Minolta description", Quantity = 2, ListPrice = 324.43m, CatalogItemCode = "x-205"
                        },
                        new LineItem()
                        {
                            LineItemId = "7", DisplayName = "Sony-Erricson", Description = "some sony description", Quantity = 3, ListPrice = 62.13m, CatalogItemCode = "x-206"
                        },
                        new LineItem()
                        {
                            LineItemId = "8", DisplayName = "Booty-Sony", Description = "some boty description", Quantity = 1, ListPrice = 8.03m, CatalogItemCode = "x-207"
                        }
                    };
                    var orderForm = new OrderForm()
                    {
                        OrderFormId = "21", Status = "Processing"
                    };
                    foreach (var lineItem in lineItems)
                    {
                        lineItem.ExtendedPrice = lineItem.Quantity * lineItem.ListPrice;
                        lineItem.PlacedPrice   = lineItem.ListPrice;
                        orderForm.LineItems.Add(lineItem);
                    }

                    // Status = "OnHold",
                    // Status = "InventoryAssigned",
                    // Status = "Packing"
                    var shipment1 = new Shipment()
                    {
                        ShipmentId = "13341-23", ShippingMethodId = "Ground Shipping", ShippingMethodName = "Ground Shipping", ShippingAddressId = "1", ShipmentTotal = 213.12m, Subtotal = 119, ShippingDiscountAmount = 5.99m
                    };
                    shipment1.ShipmentItems.Add(new ShipmentItem()
                    {
                        LineItemId = "1", Quantity = 3
                    });
                    shipment1.ShipmentItems.Add(new ShipmentItem()
                    {
                        LineItemId = "2", Quantity = 4
                    });
                    shipment1.ShipmentItems.Add(new ShipmentItem()
                    {
                        LineItemId = "3", Quantity = 6
                    });
                    shipment1.ShipmentItems.Add(new ShipmentItem()
                    {
                        LineItemId = "4", Quantity = 9
                    });
                    shipment1.ShipmentItems.Add(new ShipmentItem()
                    {
                        LineItemId = "5", Quantity = 1
                    });

                    foreach (var shipmentItem in shipment1.ShipmentItems)
                    {
                        shipmentItem.Shipment = shipment1;
                    }

                    // Status = "AwaitingInventory"
                    // Status = "InventoryAssigned"
                    // Status = "Packing"
                    var shipment2 = new Shipment()
                    {
                        ShipmentId = "1499-67", ShippingMethodId = "USPS", ShippingMethodName = "USPS", ShippingAddressId = "2", ShipmentTotal = 913.82m, Subtotal = 900.99m, ShippingDiscountAmount = 55.9m
                    };
                    shipment2.ShipmentItems.Add(new ShipmentItem()
                    {
                        LineItemId = "6", Quantity = 2
                    });
                    shipment2.ShipmentItems.Add(new ShipmentItem()
                    {
                        LineItemId = "7", Quantity = 3
                    });
                    shipment2.ShipmentItems.Add(new ShipmentItem()
                    {
                        LineItemId = "8", Quantity = 1
                    });

                    foreach (var shipmentItem in shipment2.ShipmentItems)
                    {
                        shipmentItem.Shipment = shipment2;
                    }

                    orderForm.Shipments.Add(shipment1);
                    shipment1.OrderForm = orderForm;

                    orderForm.Shipments.Add(shipment2);
                    shipment2.OrderForm = orderForm;

                    order.OrderForms.Add(orderForm);
                    orderForm.OrderGroup = order;


                    foreach (var payment in payments)
                    {
                        orderForm.Payments.Add(payment);
                    }
                    MockPaymentList.AddRange(payments);

                    foreach (var orderAddress in orderAddresses)
                    {
                        order.OrderAddresses.Add(orderAddress);
                    }

                    var rmaItems = new RmaReturnItem[] {
                        new RmaReturnItem {
                            ItemState = "AwaitingReturn", ReturnAmount = 21.32m, ReturnReason = "Corrupt"
                        },
                        new RmaReturnItem {
                            ItemState = "Received", ReturnAmount = 210.67m, ReturnReason = "Other"
                        }
                    };
                    rmaItems[0].RmaLineItems.Add(new RmaLineItem()
                    {
                        LineItemId = "8", Quantity = 1
                    });
                    rmaItems[1].RmaLineItems.Add(new RmaLineItem()
                    {
                        LineItemId = "1", Quantity = 2
                    });

                    var rmaRequest = new RmaRequest()
                    {
                        RmaRequestId = "RMA-13", Status = "AwaitingCompletion", ReturnTotal = 323.21m, RefundAmount = 301.89m, ReturnAddressId = "1", Order = order
                    };
                    foreach (var rmaItem in rmaItems)
                    {
                        rmaRequest.RmaReturnItems.Add(rmaItem);
                    }
                    order.RmaRequests.Add(rmaRequest);
                }

                // ------------
                MockShippingOptionList.AddRange(GetAllShippingOptions());
                MockPaymentMethodList.AddRange(GetAllPaymentMethods());
                MockCountryList.AddRange(GetAllCountries());
            }
        }
 /// <summary>
 /// Reorder line item indexes in all shipments after delete an item
 /// </summary>
 /// <param name="orderForm">order form</param>
 /// <param name="lineItem">removed line item</param>
 protected void ReorderIndexes(OrderForm orderForm, LineItem lineItem)
 {
     int lineItemIndex = orderForm.LineItems.IndexOf(lineItem);
     foreach (var ship in orderForm.Shipments.ToArray())
     {
         IEnumerable<int> listIdx = ship.LineItemIndexes.Select(c => Convert.ToInt32(c)).Where(i => i > lineItemIndex);
         foreach (int idx in listIdx)
         {
             ship.RemoveLineItemIndex(idx);
             ship.AddLineItemIndex(idx - 1);
         }
     }
 }
 public void MakeOrder(OrderForm orderForm)
 {
     _orders.Process(orderForm);
 }
Example #15
0
 private void ordersToolStripMenuItemClick(object sender, System.EventArgs e)
 {
     OrderForm.Show();
     OrderForm.WindowState = FormWindowState.Maximized;
 }
 /// <summary>
 /// This method is called before the order is completed. This method should check all the parameters
 /// and validate the credit card or other parameters accepted.
 /// </summary>
 /// <param name="form"></param>
 /// <returns>bool</returns>
 public Mediachase.Commerce.Orders.Payment PreProcess(OrderForm form)
 {
     OtherPayment otherPayment = new OtherPayment { TransactionType = TransactionType.Authorization.ToString() };
     return (Mediachase.Commerce.Orders.Payment)otherPayment;
 }
        public ActionResult Order(OrderForm orderForm)
        {
            Session["order"] = orderForm;

            return(RedirectToAction("OrderSum"));
        }
Example #18
0
 public PlaceOrderCommand(OrderForm orderForm)
 {
     this.orderForm = orderForm;
 }
Example #19
0
        private static void Final()
        {
            /*
             * Display the WAG welcome, and prompt
             * the user to choose the order type
             */
            WagIntro myWagIntro    = new WagIntro();
            string   userOrderType = myWagIntro.OrderType();


            /*
             * Display the order form details based on Order Type choice
             */
            OrderForm myOrder = new OrderForm();

            myOrder.UserOrderForm(userOrderType);


            /*
             * Prompt user for Gadget size
             */
            #region GadgetSize
            GadgetSizeChoice myGadgetSize = new GadgetSizeChoice();

            string userGadgetSizeEntered = myGadgetSize.ChooseGadgetSize();

            switch (userGadgetSizeEntered)
            {
            case "S":
                userGadgetSizeEntered = "Small";
                break;

            case "M":
                userGadgetSizeEntered = "Medium";
                break;

            case "L":
                userGadgetSizeEntered = "Large";
                break;
            }
            #endregion


            /*
             * Prompt user to enter number of Gadgets to order
             */
            #region GadgetNumber
            Console.WriteLine();
            Console.WriteLine("Place order for how many " + userGadgetSizeEntered + " Gadgets ? ");
            Console.WriteLine();


            int numUserGadgetsEntered;

            String Result = Console.ReadLine();

            while (!Int32.TryParse(Result, out numUserGadgetsEntered))
            {
                Console.WriteLine("Not a valid number, try again.");

                Result = Console.ReadLine();
            }

            if (numUserGadgetsEntered < 0)
            {
                Console.WriteLine("You entered a negative number.  Converting to positive.");
                numUserGadgetsEntered = Math.Abs(numUserGadgetsEntered);
            }
            #endregion


            /*
             * Prompt user for Gadget power source, and display order details
             */
            #region PowerSourceAndDetails
            string powerSelection = "";

            OrderCheckOut myCheckOut = new OrderCheckOut();

            switch (userGadgetSizeEntered)
            {
            case "Small":
                myCheckOut.DisplayOrder(userGadgetSizeEntered, "B");
                powerSelection = "B";
                break;

            case "Medium":
                PowerSource selectedPowerSourceMedium = new PowerSource();
                string      powerMedium = selectedPowerSourceMedium.UserPowerSourceMedium();
                powerSelection = powerMedium;

                myCheckOut.DisplayOrder(userGadgetSizeEntered, powerMedium);
                break;

            case "Large":
                PowerSource selectedPowerSourceLarge = new PowerSource();
                string      powerLarge = selectedPowerSourceLarge.UserPowerSourceLarge();
                powerSelection = powerLarge;

                myCheckOut.DisplayOrder(userGadgetSizeEntered, powerLarge);
                break;
            }
            #endregion

            #region UnsuedInterfaceCode

            /*
             * Console.WriteLine(" ");
             * Console.WriteLine(" ");
             * Console.WriteLine(" ");
             * Console.WriteLine(" ");
             * Console.WriteLine(" ");
             *
             * Console.WriteLine(" ");
             * Console.WriteLine(" ");
             * Console.WriteLine(" ");
             * Console.WriteLine(" ");
             * Console.WriteLine(" ");
             *
             * WidgetSmall mySmallWidget1 = new WidgetSmall();
             * mySmallWidget1.DisplaySmallWidgetComponents();     //this works because WidgetSmall.cs automatically inherits from the abstract Widget.cs
             * Console.WriteLine();
             * Console.WriteLine();
             *
             * WidgetMedium myMediumWidget1 = new WidgetMedium();
             * myMediumWidget1.DisplayMediumWidgetComponents();   //this works because WidgetMedium.cs automatically inherits from the abstract Widget.cs
             * Console.WriteLine();
             * Console.WriteLine();
             *
             * WidgetLarge myLargeWidget1 = new WidgetLarge();
             * myLargeWidget1.DisplayLargeWidgetComponents();     //this works because WidgetLarge.cs automatically inherits from the abstract Widget.cs
             * Console.WriteLine();
             * Console.WriteLine();
             */
            #endregion


            Console.WriteLine(" ");
            Console.WriteLine(" ");

            #region OrderCart
            OrderCart myCurrentOrder = new OrderCart();
            myCurrentOrder.MyOrderCart(numUserGadgetsEntered, powerSelection);

            DisplayPricing myPriceDisplay = new DisplayPricing();
            myPriceDisplay.DisplayCurrentOrder(userGadgetSizeEntered, numUserGadgetsEntered, powerSelection);
            #endregion


            Console.WriteLine();
            Console.WriteLine("Press ENTER to continue with another order, or Q + ENTER to quit...");
            Console.WriteLine();

            string userInput = Console.ReadLine().ToUpper();
            if (userInput == "Q")
            {
                Environment.Exit(0);
            }
            else
            {
                Console.Clear();
                Final();
            }
        }
Example #20
0
 public static Seat UpdateOrderForm(Seat seat, OrderForm orderForm)
 {
     seat.orderForm = orderForm.list;
     seat.total     = orderForm.total;
     return(seat);
 }
Example #21
0
 public Refund Build(Refund refund, IOrderGroup orderGroup, OrderForm returnOrderForm, IPayment payment)
 {
     // Here you can make changes to refund if needed
     return(refund);
 }
        /// <summary>
        /// Called by the workflow runtime to execute an activity.
        /// </summary>
        /// <param name="executionContext">The <see cref="T:Mediachase.Commerce.WorkflowCompatibility.ActivityExecutionContext"/> to associate with this <see cref="T:Mediachase.Commerce.WorkflowCompatibility.Activity"/> and execution.</param>
        /// <returns>
        /// The <see cref="T:Mediachase.Commerce.WorkflowCompatibility.ActivityExecutionStatus"/> of the run task, which determines whether the activity remains in the executing state, or transitions to the closed state.
        /// </returns>
        protected override ActivityExecutionStatus Execute(ActivityExecutionContext executionContext)
        {
            // Check for multiple warehouses. In the default, we simply reject processing an order if the application has
            //  multiple warehouses. Any corresponding fulfillment process is the responsibility of the client.
            CheckMultiWarehouse();

            // Validate the properties at runtime
            ValidateRuntime();

            // Return close status if order group is Payment Plan
            if (OrderGroup is PaymentPlan)
            {
                return(ActivityExecutionStatus.Closed);
            }

            var orderGroupStatus  = OrderStatusManager.GetOrderGroupStatus(OrderGroup);
            var orderForms        = OrderGroup.OrderForms.Where(o => !OrderForm.IsReturnOrderForm(o));
            var inventoryRequests = new List <InventoryRequestItem>();

            foreach (OrderForm orderForm in orderForms)
            {
                foreach (Shipment shipment in orderForm.Shipments)
                {
                    if (!ValidateShipment(orderForm, shipment))
                    {
                        continue;
                    }

                    var  shipmentStatus  = OrderStatusManager.GetOrderShipmentStatus(shipment);
                    bool completingOrder = orderGroupStatus == OrderStatus.Completed || shipmentStatus == OrderShipmentStatus.Shipped;
                    bool cancellingOrder = orderGroupStatus == OrderStatus.Cancelled || shipmentStatus == OrderShipmentStatus.Cancelled;
                    _logger.Debug(string.Format("Adjusting inventory, got orderGroupStatus as {0} and shipmentStatus as {1}. completingOrder as {2} and cancellingOrder as {3}.", orderGroupStatus, shipmentStatus, completingOrder, cancellingOrder));

                    // When completing/cancelling an order or a shipment
                    if (completingOrder || cancellingOrder)
                    {
                        var requestType = completingOrder ? InventoryRequestType.Complete : InventoryRequestType.Cancel;
                        inventoryRequests.AddRange(GetRequestInventory(shipment, inventoryRequests.Count, requestType));
                        // When processed request, need to clear all operation keys from the shipment
                        shipment.ClearOperationKeys();
                    }
                    // When release a shipment, check if shipment contain a BackOrder then need to complete that BackOrder.
                    else if (shipmentStatus == OrderShipmentStatus.Released)
                    {
                        foreach (LineItem lineItem in Shipment.GetShipmentLineItems(shipment))
                        {
                            var lineItemIndex            = orderForm.LineItems.IndexOf(lineItem);
                            var completeBackOrderRequest = new List <InventoryRequestItem>();
                            var lineItemRequest          = GetLineItemRequestInventory(shipment, lineItemIndex, 0, InventoryRequestType.Complete);

                            // Only need to process complete BackOrder request type
                            foreach (var request in lineItemRequest)
                            {
                                InventoryRequestType requestType;
                                InventoryChange      change;
                                _operationKeySerializer.Service.TryDeserialize(request.OperationKey, out requestType, out change);
                                if (requestType == InventoryRequestType.Backorder)
                                {
                                    // Add BackOrder request to request list
                                    completeBackOrderRequest.Add(request);

                                    // Then remove BackOrder request operation key from shipment's operation key map
                                    shipment.RemoveOperationKey(lineItemIndex, request.OperationKey);
                                }
                            }

                            // Storage the response operation keys from complete BackOrder mapping with line item index
                            if (completeBackOrderRequest.Count > 0)
                            {
                                InventoryResponse response = _inventoryService.Service.Request(new InventoryRequest(DateTime.UtcNow, completeBackOrderRequest, null));
                                if (response != null && response.IsSuccess)
                                {
                                    shipment.InsertOperationKeys(lineItemIndex, response.Items.Select(c => c.OperationKey));
                                }
                            }
                        }
                    }
                    else if (orderGroupStatus == OrderStatus.InProgress || orderGroupStatus == OrderStatus.AwaitingExchange)
                    {
                        // When placing an order or creating an exchange order
                        bool placingOrder = shipmentStatus == OrderShipmentStatus.AwaitingInventory || shipmentStatus == OrderShipmentStatus.InventoryAssigned;
                        if (placingOrder)
                        {
                            var lineItems = Shipment.GetShipmentLineItems(shipment);

                            CancelOperationKeys(shipment);
                            foreach (LineItem lineItem in lineItems)
                            {
                                RequestInventory(orderForm, shipment, lineItem);
                            }
                        }
                    }
                }
            }

            if (inventoryRequests.Any())
            {
                _inventoryService.Service.Request(new InventoryRequest(DateTime.UtcNow, inventoryRequests, null));
            }

            // Retun the closed status indicating that this activity is complete.
            return(ActivityExecutionStatus.Closed);
        }
 private OrderAddress GetAddressByName(OrderForm form, string name)
 {
     return(form.Parent.OrderAddresses.Cast <OrderAddress>().FirstOrDefault(address => address.Name.Equals(name)));
 }
        private void SplitForm(OrderForm form)
        {
            foreach (var item in form.LineItems)
            {
                Shipment itemShipment = null;

                // Find appropriate shipment for item
                foreach (var shipment in form.Shipments)
                {
                    if (shipment.ShippingMethodId == item.ShippingMethodId &&
                        string.CompareOrdinal(shipment.ShippingAddressId, item.ShippingAddressId) == 0 &&
                        string.Compare(shipment.FulfillmentCenterId, item.FulfillmentCenterId, StringComparison.OrdinalIgnoreCase) == 0)
                    {
                        // we found out match, exit
                        itemShipment = shipment;
                        //break;
                    }
                    else
                    {
                        // if shipment contains current LineItem, remove it from the shipment
                        RemoveLineItemFromShipment(shipment, item.LineItemId);
                    }
                }

                // did we find any shipment?
                if (itemShipment == null)
                {
                    itemShipment = new Shipment
                    {
                        ShippingAddressId   = item.ShippingAddressId,
                        ShippingMethodId    = item.ShippingMethodId,
                        ShippingMethodName  = item.ShippingMethodName,
                        FulfillmentCenterId = item.FulfillmentCenterId,
                        OrderForm           = form
                    };
                    form.Shipments.Add(itemShipment);
                }

                // Add item to the shipment
                //if (item.LineItemId == 0)
                //    throw new ArgumentNullException("LineItemId = 0");

                RemoveLineItemFromShipment(itemShipment, item.LineItemId);

                var link = new ShipmentItem
                {
                    LineItemId = item.LineItemId,
                    LineItem   = item,
                    Quantity   = item.Quantity,
                    ShipmentId = itemShipment.ShipmentId
                };
                itemShipment.ShipmentItems.Add(link);
            }

            //Clear unused shipments
            foreach (var shipment in form.Shipments.ToArray())
            {
                if (shipment.ShipmentItems.Count == 0)
                {
                    form.Shipments.Remove(shipment);
                }
            }
        }
        public ActionResult OrderSumPost()
        {
            OrderForm orderForm = (OrderForm)Session["order"];
            CartModel cart      = (CartModel)Session["cart"];

            OrderModel order = new OrderModel();

            order.Firstname    = orderForm.Firstname;
            order.Lastname     = orderForm.Lastname;
            order.Locality     = orderForm.Locality;
            order.Street       = orderForm.Street;
            order.Zipcode      = orderForm.Zipcode;
            order.Phone        = orderForm.Phone;
            order.Shipment     = orderForm.Shipment;
            order.Date         = DateTime.Now;
            order.Description  = orderForm.Description;
            order.orderDetails = new Collection <OrderDetailModel>();

            UserDetails ud = null;

            if (orderForm.Remember == true)
            {
                try
                {
                    string query = "SELECT * FROM UserDetails WHERE Email = @email";
                    ud           = db.UserDetails.SqlQuery(query, new SqlParameter("@email", User.Identity.GetUserName())).First();
                    ud.Firstname = orderForm.Firstname;
                    ud.Lastname  = orderForm.Lastname;
                    ud.Locality  = orderForm.Locality;
                    ud.Street    = orderForm.Street;
                    ud.Zipcode   = orderForm.Zipcode;
                    ud.Phone     = orderForm.Phone;

                    db.Entry(ud).State = EntityState.Modified;
                    db.SaveChanges();
                }
                catch (Exception e)
                {
                    ud = new UserDetails();

                    ud.Firstname = orderForm.Firstname;
                    ud.Lastname  = orderForm.Lastname;
                    ud.Locality  = orderForm.Locality;
                    ud.Street    = orderForm.Street;
                    ud.Zipcode   = orderForm.Zipcode;
                    ud.Phone     = orderForm.Phone;
                    ud.Email     = User.Identity.GetUserName();

                    db.UserDetails.Add(ud);

                    db.SaveChanges();
                }
            }
            else
            {
                try
                {
                    string query = "SELECT * FROM UserDetails WHERE Email = @email";
                    ud = db.UserDetails.SqlQuery(query, new SqlParameter("@email", User.Identity.GetUserName())).First();
                }
                catch (Exception e)
                {
                    ud = new UserDetails();

                    ud.Firstname = orderForm.Firstname;
                    ud.Lastname  = orderForm.Lastname;
                    ud.Locality  = orderForm.Locality;
                    ud.Street    = orderForm.Street;
                    ud.Zipcode   = orderForm.Zipcode;
                    ud.Phone     = orderForm.Phone;
                    ud.Email     = User.Identity.GetUserName();

                    db.UserDetails.Add(ud);

                    db.SaveChanges();
                }
            }

            foreach (var item in cart.products)
            {
                ProductModel p = item.Key;
                int          q = item.Value;

                if (p.Quantity >= q)
                {
                    p.Quantity       -= q;
                    db.Entry(p).State = EntityState.Modified;
                }
                else
                {
                    Session["order"] = null;
                    Session["cart"]  = null;

                    return(RedirectToAction("OrderResultUnsuccessful"));
                }

                OrderDetailModel od = new OrderDetailModel();
                od.product  = p;
                od.Quantity = q;

                db.OrderDetail.Add(od);

                order.orderDetails.Add(od);
            }

            order.user = ud;
            db.Order.Add(order);
            db.SaveChanges();

            Session["order"] = null;
            Session["cart"]  = null;

            return(RedirectToAction("OrderResult"));
        }
 public CreateOrderCommand(OrderForm orderForm)
 {
     this.orderForm = orderForm;
 }
Example #27
0
 public MainWindow()
 {
     InitializeComponent();
     this.orderForm = new OrderForm();
     this.a4size    = this.A4Size();
 }
        private void stockPertamaxOrderBtn_Click(object sender, EventArgs e)
        {
            OrderForm newOrderForm = new OrderForm();

            newOrderForm.ShowDialog(this);
        }
Example #29
0
 public void UpdateOrderEntity(Order order, OrderForm orderForm)
 {
     order.Comments    = orderForm.OrderComments;
     order.TableNumber = order.TableNumber;
 }
        private void RequestInventory(OrderForm orderForm, Shipment shipment, LineItem lineItem)
        {
            var lineItemIndex = orderForm.LineItems.IndexOf(lineItem);
            InventoryRequest request;
            var outOfStock = false;
            InventoryResponse response = null;

            lock (_lockObject)
            {
                // Check quantity of order again to make sure there is enough quantity.
                outOfStock = this.GetNewLineItemQty(lineItem, new List<string>(), shipment) <= 0;

                if (!outOfStock)
                {
                    request = AdjustStockItemQuantity(shipment, lineItem);
                    if (request != null)
                    {
                        response = _inventoryService.Service.Request(request);
                    }
                }
            }

            // if out of stock, delete line item and remove line item from the shipment.
            if (outOfStock)
            {
                Warnings.Add("LineItemRemoved-" + lineItem.LineItemId.ToString(), String.Format("Item \"{0}\" has been removed from the cart because there is not enough available quantity.", lineItem.DisplayName));
                lineItem.Delete();
                shipment.RemoveLineItemIndex(lineItemIndex);

                // Delete the shipment and cancel operation keys if it has no more line item.
                if (shipment.LineItemIndexes.Length == 0)
                {
                    CancelOperationKeys(shipment);
                    shipment.Delete();
                    shipment.AcceptChanges();
                }
                return;
            }

            if (response != null && response.IsSuccess)
            {
                lineItem.IsInventoryAllocated = true;

                // Store operation keys to Shipment for each line item, to use later for complete request
                var existedIndex = shipment.OperationKeysMap.ContainsKey(lineItemIndex);
                var operationKeys = response.Items.Select(c => c.OperationKey);
                if (!existedIndex)
                {
                    shipment.AddInventoryOperationKey(lineItemIndex, operationKeys);
                }
                else
                {
                    shipment.InsertOperationKeys(lineItemIndex, operationKeys);
                }
            }
        }
 private OrderAddress GetAddressByName(OrderForm form, string name)
 {
     return form.Parent.OrderAddresses.Cast<OrderAddress>().FirstOrDefault(address => address.Name.Equals(name));
 }
Example #32
0
        public IHttpActionResult PostOrder(OrderForm orderForm)
        {
            var emailId = db.Registeration.Where(r => r.Email.ToLower() == orderForm.customerId.ToLower()).FirstOrDefault();

            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            var cartItems = (from c in db.Carts.ToList()
                             where c.customerId == orderForm.customerId
                             select c).ToList();

            foreach (var item in cartItems)
            {
                // Check available quantity of pizza
                int availableQuantity = db.PizzaStocks.Where((ps) => ps.pizzaId == item.pizzaId).Select(p => p.quantity).First();

                if (availableQuantity < item.quantity)
                {
                    return(BadRequest($"Sufficient quantity of {item.pizzaName} pizza is not available!"));
                }
            }


            // Check delivery executive availability
            var deliveryExecs = from d in db.Registeration.ToList()
                                where (d.UserType == "Delivery") && (d.IsActive == true)
                                select d;

            if (deliveryExecs.Count() == 0)
            {
                return(BadRequest("No Delivery Executive available for delivery!"));
            }

            // Get delivery executive
            var delExec = deliveryExecs.First();

            delExec.IsActive = false;



            // Create Order object
            Order order = new Order
            {
                status            = orderForm.status,
                totalAmount       = orderForm.totalAmount,
                timeStamp         = orderForm.timeStamp,
                DeliveryExecutive = delExec
            };

            order.customer = emailId;

            // Add to db
            db.Orders.Add(order);

            // Get pizzas added to the cart for this customer
            var pizzaIds = (from c in db.Carts.ToList()
                            where c.customerId == orderForm.customerId
                            select c).ToList();

            // Create OrderDetail objects
            foreach (var pid in pizzaIds)
            {
                // Get Pizza using pizzaId
                Pizza pizza = db.Pizzas.Find(pid.pizzaId);

                // Set order and pizza of orderDetail
                OrderDetail orderDetail = new OrderDetail
                {
                    Order     = order,
                    Pizza     = pizza,
                    quantity  = pid.quantity,
                    pizzaSize = pid.pizzaSize,
                    price     = pid.pizzaPrice,
                };

                var pizzaStockItem = (from p in db.PizzaStocks.ToList()
                                      where p.pizzaId == pid.pizzaId
                                      select p).First();

                pizzaStockItem.quantity -= pid.quantity;

                db.MarkAsModified(pizzaStockItem);

                db.OrderDetails.Add(orderDetail);
            }

            // Remove cart items
            var carts = (from c in db.Carts.ToList()
                         where c.customerId == orderForm.customerId
                         select c).ToList();

            foreach (var item in carts)
            {
                db.Carts.Remove(item);
            }

            // Commit changes to db
            db.SaveChanges();
            return(Ok(order));
        }
        public bool PostProcess(OrderForm orderForm)
        {
            var card = orderForm.Payments.ToArray().FirstOrDefault(x => x.PaymentType == PaymentType.CreditCard);
            if (card == null)
                return false;

            card.Status = PaymentStatus.Processed.ToString();
            card.AcceptChanges();
            return true;
        }
Example #34
0
        public bool AddProduct(DataRow[] dr, bool isBarcode, string barcode)
        {
            bool next = false;


            float kg = -1;

            if (isBarcode && dr.Length == 0)
            {
                //object[] obj = getProductWithMassa(barcode);
                //dr = (DataRow[])obj[0];
                //kg = (float)obj[1];
                dr = getProductWithMassa(barcode);
            }

            if (dr.Length != 0)
            {
                DataSetTpos.productRow drP = (DataSetTpos.productRow)dr[0];
                DataRow[] existRows        = DBclass.DS.orders.Select("expenseId=-1 and prodId = " + drP.productId);
                if (existRows.Length > 0)
                {
                    DataSetTpos.ordersRow ordrow = (DataSetTpos.ordersRow)existRows[0];
                    ordrow.packCount = ordrow.packCount + (drP.pack == 0 ? 1 : drP.pack);
                    DataRow drOrder = ordrow;
                    drOrder["sumProduct"] = ordrow.packCount * drP.price / (drP.pack == 0 ? 1 : drP.pack);//ordrow.AcceptChanges();
                }
                else
                {
                    DataSetTpos.ordersRow ordrow = DBclass.DS.orders.NewordersRow();



                    ordrow.prodId = drP.productId;
                    if (drP.pack == 0)
                    {
                        drP.pack = 1;
                    }
                    ordrow.expenseId = -1;
                    float     curPrice = drP.price;
                    OrderForm oform    = new OrderForm(drP);
                    System.Windows.Forms.DialogResult result = oform.ShowDialog();
                    if (result == System.Windows.Forms.DialogResult.OK)
                    {
                        ordrow.packCount = (float)oform.count;
                        DataRow drOrder = ordrow;
                        drOrder["sumProduct"] = oform.sum;//ordrow.packCount * drP.price / (drP.pack == 0 ? 1 : drP.pack);
                        ordrow.orderSumm      = Convert.ToSingle(drOrder["sumProduct"]);

                        //grid.Rows[e.RowIndex].Cells["sumProduct"].Value = (Convert.ToInt32(grid.Rows[e.RowIndex].Cells["packCount"].Value) * Convert.ToInt32(grid.Rows[e.RowIndex].Cells["productPrice"].Value)).ToString();
                    }
                    else if (result == System.Windows.Forms.DialogResult.Cancel)
                    {
                        //ordrow.RejectChanges();
                        drP.RejectChanges();
                        return(false);
                    }
                    else
                    {
                        if (drP.price == 0)
                        {
                            System.Windows.Forms.MessageBox.Show("Товар на складе отсутствует");
                            drP.RejectChanges();
                        }
                        return(false);
                    }
                    DBclass.DS.orders.AddordersRow(ordrow);
                    if (curPrice != drP.price && drP.price != 0)
                    {
                        productTableAdapter prda = new productTableAdapter();
                        prda.Update(drP);
                        return(true);
                    }
                }
                if (isNewExpense)
                {
                    //dgvExpense.Columns["productName"].Visible = true;
                    //dgvExpense.Columns["productPrice"].Visible = true;
                    isNewExpense = false;
                }
                //sumTable();
            }
            else if (isBarcode && UserValues.role == "admin")
            {
                AddForm addForm = new AddForm(barcode);
                if (addForm.ShowDialog() == System.Windows.Forms.DialogResult.OK)
                {
                    //productTableAdapter daProduct = new productTableAdapter();
                    //daProduct.Fill(DBclass.DS.product);
                }
            }

            next = true;
            return(true);
        }
Example #35
0
        private void OrdersButton_Click(object sender, EventArgs e)
        {
            OrderForm orderForm = new OrderForm(currentUser);

            orderForm.ShowDialog();
        }
        /// <summary>
        /// Gets the name of the address by name.
        /// </summary>
        /// <param name="form">The form.</param>
        /// <param name="name">The name.</param>
        /// <returns></returns>
        private OrderAddress GetAddressByName(OrderForm form, string name)
        {
            foreach (OrderAddress address in form.Parent.OrderAddresses)
            {
                if (address.Name.Equals(name))
                    return address;
            }

            return null;
        }
 /// <summary>
 /// This method is called after the order is placed. This method should be used by the gateways that want to
 /// redirect customer to their site.
 /// </summary>
 /// <param name="orderForm">The form.</param>
 /// <returns></returns>
 public bool PostProcess(OrderForm orderForm)
 {
     return true;
 }
        public Mediachase.Commerce.Orders.Payment PreProcess(OrderForm orderForm)
        {
            if (orderForm == null) throw new ArgumentNullException("orderForm");

            if (!ValidateData())
                return null;

            var payment = new CreditCardPayment
                {
                    CardType = "Credit card",
                    PaymentMethodId = PaymentMethodId,
                    PaymentMethodName = "GenericCreditCard",
                    OrderFormId = orderForm.OrderFormId,
                    OrderGroupId = orderForm.OrderGroupId,
                    Amount = orderForm.Total,
                    CreditCardNumber = CreditCardNumber,
                    CreditCardSecurityCode = CreditCardSecurityCode,
                    ExpirationMonth = ExpirationMonth,
                    ExpirationYear = ExpirationYear,
                    Status = PaymentStatus.Pending.ToString(),
                    CustomerName = CreditCardName,
                    TransactionType = TransactionType.Authorization.ToString()
            };

            return payment;
        }
        /// <summary>
        /// Calculates the totals order forms.
        /// </summary>
        /// <param name="form">The form.</param>
        private void CalculateTotalsOrderForms(OrderForm form)
        {
            decimal subTotal = 0m;
            decimal discountTotal = 0m;
            decimal shippingDiscountTotal = 0m;
            decimal shippingTotal = 0m;

            foreach (LineItem item in form.LineItems.Where(x => x.ObjectState != MetaObjectState.Deleted))
            {
                decimal lineItemDiscount = item.LineItemDiscountAmount + item.OrderLevelDiscountAmount;
                item.ExtendedPrice = item.PlacedPrice * item.Quantity - lineItemDiscount;
                subTotal += item.ExtendedPrice;
                discountTotal += lineItemDiscount;
            }

            foreach (Shipment shipment in form.Shipments.Where(x=> x.ObjectState != MetaObjectState.Deleted))
            {
                shipment.SubTotal = CalculateShipmentSubtotal(shipment);
                shippingTotal += shipment.ShippingSubTotal;
                shippingTotal -= shipment.ShippingDiscountAmount;
                shippingDiscountTotal += shipment.ShippingDiscountAmount;
            }

            form.ShippingTotal = shippingTotal;
            form.DiscountAmount = discountTotal + shippingDiscountTotal;
            form.SubTotal = subTotal;

            form.Total = subTotal + shippingTotal + form.TaxTotal;

            //Calculate payment total
            var formPayments = form.Payments.ToArray();
            var resultingAuthorizedPayments = base.GetResultingPaymentsByTransactionType(formPayments, TransactionType.Authorization);
            var resultingCapturedPayments = base.GetResultingPaymentsByTransactionType(formPayments, TransactionType.Capture);
            var resultingSalsePayments = base.GetResultingPaymentsByTransactionType(formPayments, TransactionType.Sale);
            var resultingCreditPayments = base.GetResultingPaymentsByTransactionType(formPayments, TransactionType.Credit);

            form.AuthorizedPaymentTotal = resultingAuthorizedPayments.Where(x => PaymentStatusManager.GetPaymentStatus(x) == PaymentStatus.Processed).Sum(y => y.Amount);
            form.CapturedPaymentTotal = resultingSalsePayments.Where(x => PaymentStatusManager.GetPaymentStatus(x) == PaymentStatus.Processed).Sum(y => y.Amount);
            form.CapturedPaymentTotal += resultingCapturedPayments.Where(x => PaymentStatusManager.GetPaymentStatus(x) == PaymentStatus.Processed).Sum(y => y.Amount);
            form.CapturedPaymentTotal -= resultingCreditPayments.Where(x => PaymentStatusManager.GetPaymentStatus(x) == PaymentStatus.Processed).Sum(y => y.Amount);
        }
        /// <summary>
        /// Creates the set from order form.
        /// </summary>
        /// <param name="form">The form.</param>
        /// <returns></returns>
        private PromotionEntriesSet CreateSetFromOrderForm(OrderForm form)
        {
            PromotionEntriesSet set = new PromotionEntriesSet();
            set.OrderFormId = form.OrderFormId.ToString();

            IOrderedEnumerable<LineItem> lineItemByPrice = form.LineItems.ToArray().Where(x => !IsGiftLineItem(x)).OrderByDescending(x => x.PlacedPrice);

            foreach (LineItem lineItem in lineItemByPrice)
            {
                set.Entries.Add(CreatePromotionEntryFromLineItem(lineItem));
            }

            return set;
        }
 public void AddOrderForm(OrderForm newOrderForm)
 {
     _context.OrderForms.Add(newOrderForm);
     _context.SaveChanges();
 }
Example #42
0
        /// <summary>
        /// This method is called before the order is completed. This method should check all the parameters
        /// and validate the credit card or other parameters accepted.
        /// </summary>
        /// <param name="form"></param>
        /// <returns>bool</returns>
        public Payment PreProcess(OrderForm form)
        {
            OtherPayment otherPayment = new OtherPayment();

            return((Payment)otherPayment);
        }
 /// <summary>
 /// This method is called after the order is placed. This method should be used by the gateways that want to
 /// redirect customer to their site.
 /// </summary>
 /// <param name="orderForm">The order form.</param>
 /// <param name="model">The model.</param>
 /// <returns><c>true</c></returns>
 public bool PostProcess(OrderForm orderForm, PaymentModel model)
 {
     return(true);
 }
        private void orderFormButton_Click(object sender, EventArgs e)
        {
            OrderForm aOrderForm = new OrderForm();

            aOrderForm.Show();
        }
 /// <summary>
 /// This method is called after the order is placed. This method should be used by the gateways that want to
 /// redirect customer to their site.
 /// </summary>
 /// <param name="orderForm">The order form.</param>
 public bool PostProcess(OrderForm orderForm)
 {
     return(true);
 }
 /// <summary>
 /// This method is called before the order is completed. This method should check all the parameters
 /// and validate the credit card or other parameters accepted.
 /// </summary>
 /// <param name="form"></param>
 /// <returns>bool</returns>
 public Payment PreProcess(OrderForm form)
 {
     OtherPayment otherPayment = new OtherPayment();
     otherPayment.BillingAddressId = form.BillingAddressId;
     return (Payment)otherPayment;
 }
Example #47
0
 /// <summary>
 /// Updates the payment totals for an order form.
 /// </summary>
 /// <param name="orderForm">The order form</param>
 protected virtual void UpdateOrderFormPaymentTotals(OrderForm orderForm)
 {
     orderForm.UpdatePaymentTotals();
 }
 private void OrderToolStripMenuItem_Click(object sender, EventArgs e)
 {
     OrderForm orderForm = new OrderForm();
     orderForm.MdiParent = this;
     orderForm.Show();
 }
        public async Task <IActionResult> Create([Bind("Id,ReceiverName,ReceiverPhone,ReceiverAddress")] OrderForm orderForm)
        {
            var currentCart = CartManager.GetCurrentCart();

            if (ModelState.IsValid)
            {
                List <string> QuantityError = new List <string>();

                // 檢查購物車是否為空
                if (currentCart.Count() < 1)
                {
                    QuantityError.Add($"您的購物車內沒有任何東西!");
                    ViewBag.QuantityError = QuantityError;
                    return(View());
                }

                // 檢查庫存
                foreach (var p in currentCart)
                {
                    Product product = await _context.Product.FirstOrDefaultAsync(m => m.Id == p.Id);

                    if (product.Quantity < p.Quantity)
                    {
                        QuantityError.Add($"庫存不足,{product.Name}只剩{product.Quantity}個!");
                    }
                }

                if (QuantityError.Count > 0)
                {
                    ViewBag.QuantityError = QuantityError;
                    return(View());
                }

                try
                {
                    using var transaction = _context.Database.BeginTransaction();

                    // 儲存訂單
                    orderForm.CheckOut    = "NO";
                    orderForm.CreateTime  = DateTime.Now;
                    orderForm.SenderEmail = User.Identity.Name;
                    orderForm.TotalAmount = currentCart.TotalAmount;
                    _context.Add(orderForm);

                    // 先儲存才能產生訂單的Id(訂單明細會用到)
                    await _context.SaveChangesAsync();

                    // 儲存訂單明細
                    var orderDetails = new List <OrderDetail>();

                    foreach (var cartItem in currentCart)
                    {
                        orderDetails.Add(new OrderDetail()
                        {
                            OrderId  = orderForm.Id,
                            Name     = cartItem.Name,
                            Price    = cartItem.Price,
                            Quantity = cartItem.Quantity
                        });
                    }

                    _context.OrderDetail.AddRange(orderDetails);
                    await _context.SaveChangesAsync();

                    transaction.Commit();
                }
                catch (Exception e)
                {
                    _logger.LogError($"將第{orderForm.Id}筆訂單存入資料庫時發生錯誤...{e}");
                    return(View("~/Views/Shared/DataBaseBusy.cshtml"));
                }

                // 從設定檔取得 WebApi 的網域
                string MyApiDomain = ConfigManager.GetValueByKey("MyApiDomain");

                // 產生此筆交易的KEY
                string UnencryptedKey = Path.GetRandomFileName() + Path.GetRandomFileName();

                // 將 KEY 加密 & 存入Session,之後要用來驗證
                byte[] keyBytes     = Encoding.UTF8.GetBytes(UnencryptedKey + string.Join("", UnencryptedKey.Reverse()));
                string EncryptedKey = Convert.ToBase64String(keyBytes);
                using (var md5 = MD5.Create())
                {
                    var result = md5.ComputeHash(Encoding.ASCII.GetBytes(EncryptedKey));
                    EncryptedKey = BitConverter.ToString(result);
                }

                HttpContext.Session.SetInt32(EncryptedKey, orderForm.Id);

                // 傳送訂單ID、未加密的KEY、購物車給 WebApi
                _logger.LogInformation($"[{orderForm.SenderEmail}]建立了第{orderForm.Id}號訂單");
                return(Redirect($"{MyApiDomain}/Home/SendToOpay/?OrderKey={UnencryptedKey}&JsonString={JsonConvert.SerializeObject(currentCart)}"));
            }
            else
            {
                return(View());
            }
        }