public static bool IsValidAutoOrderID(int customerID, int autoOrderID, bool includeCancelledAutoOrders = false) { // Get the autoorder //var context = Exigo.OData(); //var query = context.AutoOrders // .Where(c => c.CustomerID == customerID) // .Where(c => c.AutoOrderID == autoOrderID); AutoOrder autoOrder = new AutoOrder(); using (var Context = Exigo.Sql()) { string SPGetCustomerAutoOrders = string.Format("GetCustomerAutoOrders {0},{1}", customerID, autoOrderID); autoOrder = Context.Query <AutoOrder>(SPGetCustomerAutoOrders).FirstOrDefault(); } // Only pull active auto orders if applicable //if (!includeCancelledAutoOrders) query = query.Where(c => c.AutoOrderStatusID == 1); bool isAutoOrdercancelled = true; if (!includeCancelledAutoOrders) { isAutoOrdercancelled = autoOrder.AutoOrderStatusID == 1; } if (!isAutoOrdercancelled) { autoOrder = new AutoOrder(); } // var autoOrder = query.FirstOrDefault(); return(autoOrder != null); }
public static void DeleteCustomerAutoOrder(int customerID, int autoOrderID) { // Get the autoorder //var context = Exigo.OData(); //var autoOrder = context.AutoOrders // .Where(c => c.CustomerID == customerID) // .Where(c => c.AutoOrderID == autoOrderID); AutoOrder autoOrder = new AutoOrder(); using (var Context = Exigo.Sql()) { string SPGetCustomerAutoOrders = string.Format("GetCustomerAutoOrders {0},{1}", customerID, autoOrderID); autoOrder = Context.Query <AutoOrder>(SPGetCustomerAutoOrders).FirstOrDefault(); } if (autoOrder == null) { return; } // Cancel the autoorder var response = Exigo.WebService().ChangeAutoOrderStatus(new ChangeAutoOrderStatusRequest { AutoOrderID = autoOrderID, AutoOrderStatus = AutoOrderStatusType.Deleted }); }
public static void UpdateCustomerAutoOrderShippingAddress(int customerID, int autoOrderID, ShippingAddress address) { //var context = Exigo.OData(); // Get the autoorder //var autoOrder = context.AutoOrders // .Where(c => c.CustomerID == customerID) // .Where(c => c.AutoOrderID == autoOrderID) // .FirstOrDefault(); //get auto orders from sql using following stored procedures AutoOrder autoOrder = new AutoOrder(); using (var Context = Exigo.Sql()) { string SPGetCustomerAutoOrders = string.Format("GetCustomerAutoOrders {0},{1}", customerID, autoOrderID); autoOrder = Context.Query <AutoOrder>(SPGetCustomerAutoOrders).FirstOrDefault(); } if (autoOrder == null) { return; } // Re-create the autoorder var request = GetCreateOverridenAutoOrderRequest(customerID, autoOrderID); request.FirstName = address.FirstName; request.LastName = address.LastName; request.Company = address.Company; request.Address1 = address.Address1; request.Address2 = address.Address2; request.City = address.City; request.State = address.State; request.Zip = address.Zip; request.Country = address.Country; request.Email = address.Email; request.Phone = address.Phone; // Update the autoorder var response = Exigo.WebService().CreateAutoOrder(request); }
public static AutoOrder GetCustomerAutoOrder(int customerID, int autoOrderID) { //var context = Exigo.OData(); //// Setup the base query //var autoOrderData = context.AutoOrders.Expand("Details") // .Where(c => c.CustomerID == customerID) // .Where(c => c.AutoOrderID == autoOrderID) // .FirstOrDefault(); //if (autoOrderData == null) return null; //var autoOrder = (AutoOrder)autoOrderData; // Get the payment methods if applicable var paymentMethods = GetCustomerPaymentMethods(new GetCustomerPaymentMethodsRequest { CustomerID = customerID }); //get auto orders from sql using following stored procedures var autoOrder = new AutoOrder(); using (var Context = Exigo.Sql()) { string SPGetCustomerAutoOrders = string.Format("GetCustomerAutoOrders {0},{1}", customerID, autoOrderID); autoOrder = Context.Query <AutoOrder>(SPGetCustomerAutoOrders).FirstOrDefault(); string SPGetCustomerAutoOrderDetail = string.Format("GetCustomerAutoOrderDetail {0}", autoOrderID.ToString()); var detailsList = Context.Query <AutoOrderDetail>(SPGetCustomerAutoOrderDetail).ToList(); autoOrder.Details = detailsList.ToList(); string SPGetCustomerAutoOrderShippingAddress = string.Format("GetCustomerAutoOrderShippingAddress {0}", customerID); var reciept = Context.Query <ShippingAddress>(SPGetCustomerAutoOrderShippingAddress).FirstOrDefault(); autoOrder.Recipient = reciept; } IPaymentMethod paymentMethod; switch (autoOrder.AutoOrderPaymentTypeID) { case 1: paymentMethod = paymentMethods.Where(c => c is CreditCard && ((CreditCard)c).Type == CreditCardType.Primary).FirstOrDefault(); break; case 2: paymentMethod = paymentMethods.Where(c => c is CreditCard && ((CreditCard)c).Type == CreditCardType.Secondary).FirstOrDefault(); break; case 3: paymentMethod = paymentMethods.Where(c => c is BankAccount && ((BankAccount)c).Type == ExigoService.BankAccountType.Primary).FirstOrDefault(); break; default: paymentMethod = null; break; } autoOrder.PaymentMethod = paymentMethod; // Determine if each autoship contains only virtual items if applicable //var itemIDs = new List<int>(); //if (autoOrder.Details != null && autoOrder.Details.Count() > 0) //{ // itemIDs.AddRange(autoOrder.Details.Select(c => c.ItemID)); //} //itemIDs = itemIDs.Distinct().ToList(); //// Determine which item IDs are virtual //var virtualItems = context.Items // .Where(c => c.IsVirtual) // .Where(itemIDs.ToOrExpression<Common.Api.ExigoOData.Item, int>("ItemID")) // .Select(c => new { c.ItemID }) // .ToList(); //var virtualItemIDs = virtualItems.Select(c => c.ItemID).ToList(); //// Loop through each auto order, setting the details //foreach (var detail in autoOrder.Details) //{ // if (virtualItemIDs.Contains(detail.ItemID)) // { // detail.IsVirtual = true; // } //} // Return the results return(autoOrder); }