public void SaveOrder(Order order)
        {

            //save down the addresses
            if(order.ShippingAddress!=null)
                SaveAddress(order.ShippingAddress);
            
            if(order.BillingAddress!=null)
                SaveAddress(order.BillingAddress);


            using (DB db = new DB())
            {
                
                //pull the order
                Commerce.Data.SqlRepository.Order existingOrder = (from o in db.Orders
                                                               where o.OrderID == order.ID
                                                               select o).SingleOrDefault();
                if (existingOrder == null)
                   throw new InvalidOperationException("There is no order with the ID "+order.ID.ToString());

                //marry up the orders
                existingOrder.TaxAmount=order.TaxAmount;

                if (order.ShippingMethod != null) {
                    existingOrder.ShippingAmount = order.ShippingMethod.Cost;
                    existingOrder.ShippingMethodID = order.ShippingMethod.ID;
                    
                    //shipping method bits
                    existingOrder.EstimatedDelivery = DateTime.Now.AddDays(order.ShippingMethod.DaysToDeliver);
                }
                existingOrder.SubTotal=order.SubTotal;
                existingOrder.OrderStatusID=(int)order.Status;

                if(order.ShippingAddress!=null)
                    existingOrder.ShippingAddressID = order.ShippingAddress.ID;
                
                if (order.BillingAddress != null)
                    existingOrder.BillingAddressID = order.BillingAddress.ID;
                
                existingOrder.ExecutedOn = DateTime.Now;
                existingOrder.OrderNumber = order.OrderNumber;
                existingOrder.UserName = order.UserName;
                existingOrder.DiscountAmount = order.DiscountAmount;
                existingOrder.DiscountReason = order.DiscountReason;

                //save this down so we know how to correspond in the future
                existingOrder.UserLanguageCode = System.Globalization.CultureInfo.CurrentUICulture.TwoLetterISOLanguageName;

                foreach (Transaction t in order.Transactions)
                {
                    Commerce.Data.SqlRepository.Transactions newTransaction = new Commerce.Data.SqlRepository.Transactions();

                    //a little left/right action...
                    newTransaction.TransactionID = t.ID;
                    newTransaction.OrderID = t.OrderID;
                    newTransaction.Notes = t.Notes;
                    newTransaction.AuthorizationCode = t.AuthorizationCode;
                    newTransaction.Amount = t.Amount;
                    newTransaction.ProcessorID = (int)t.Processor;
                    newTransaction.TransactionDate = t.DateExecuted;

                    db.Transactions.InsertOnSubmit(newTransaction);


                }

                //cross your fingers!
                db.SubmitChanges();
            }


        }
예제 #2
0
        public void SaveOrder(Order order)
        {
            //save down the addresses
            if (order.ShippingAddress != null)
            {
                SaveAddress(order.ShippingAddress);
            }

            if (order.BillingAddress != null)
            {
                SaveAddress(order.BillingAddress);
            }


            using (DB db = new DB())
            {
                //pull the order
                Commerce.Data.SqlRepository.Order existingOrder = (from o in db.Orders
                                                                   where o.OrderID == order.ID
                                                                   select o).SingleOrDefault();
                if (existingOrder == null)
                {
                    throw new InvalidOperationException("There is no order with the ID " + order.ID.ToString());
                }

                //marry up the orders
                existingOrder.TaxAmount = order.TaxAmount;

                if (order.ShippingMethod != null)
                {
                    existingOrder.ShippingAmount   = order.ShippingMethod.Cost;
                    existingOrder.ShippingMethodID = order.ShippingMethod.ID;

                    //shipping method bits
                    existingOrder.EstimatedDelivery = DateTime.Now.AddDays(order.ShippingMethod.DaysToDeliver);
                }
                existingOrder.SubTotal      = order.SubTotal;
                existingOrder.OrderStatusID = (int)order.Status;

                if (order.ShippingAddress != null)
                {
                    existingOrder.ShippingAddressID = order.ShippingAddress.ID;
                }

                if (order.BillingAddress != null)
                {
                    existingOrder.BillingAddressID = order.BillingAddress.ID;
                }

                existingOrder.ExecutedOn     = DateTime.Now;
                existingOrder.OrderNumber    = order.OrderNumber;
                existingOrder.UserName       = order.UserName;
                existingOrder.DiscountAmount = order.DiscountAmount;
                existingOrder.DiscountReason = order.DiscountReason;

                //save this down so we know how to correspond in the future
                existingOrder.UserLanguageCode = System.Globalization.CultureInfo.CurrentUICulture.TwoLetterISOLanguageName;

                foreach (Transaction t in order.Transactions)
                {
                    Commerce.Data.SqlRepository.Transactions newTransaction = new Commerce.Data.SqlRepository.Transactions();

                    //a little left/right action...
                    newTransaction.TransactionID     = t.ID;
                    newTransaction.OrderID           = t.OrderID;
                    newTransaction.Notes             = t.Notes;
                    newTransaction.AuthorizationCode = t.AuthorizationCode;
                    newTransaction.Amount            = t.Amount;
                    newTransaction.ProcessorID       = (int)t.Processor;
                    newTransaction.TransactionDate   = t.DateExecuted;

                    db.Transactions.InsertOnSubmit(newTransaction);
                }

                //cross your fingers!
                db.SubmitChanges();
            }
        }
 partial void DeleteTransactions(Transactions instance);
 partial void UpdateTransactions(Transactions instance);
 partial void InsertTransactions(Transactions instance);
		private void detach_Transactions(Transactions entity)
		{
			this.SendPropertyChanging();
			entity.Order = null;
		}
		private void attach_Transactions(Transactions entity)
		{
			this.SendPropertyChanging();
			entity.TransactionProcessor = this;
		}