/// <summary> /// Loads the by customer and order group id. /// </summary> /// <param name="CustomerId">The customer id.</param> /// <param name="OrderGroupId">The order group id.</param> /// <returns></returns> public static PurchaseOrder LoadByCustomerAndOrderGroupId(Guid CustomerId, int OrderGroupId) { Guid searchGuid = Guid.NewGuid(); DataCommand cmd = OrderDataHelper.CreateTranDataCommand(); cmd.CommandText = String.Format("ecf_Search_{0}_CustomerAndOrderGroupId", OrderContext.Current.PurchaseOrderMetaClass.Name); cmd.Parameters = new DataParameters(); cmd.Parameters.Add(new DataParameter("ApplicationId", OrderConfiguration.Instance.ApplicationId, DataParameterType.UniqueIdentifier)); cmd.Parameters.Add(new DataParameter("SearchSetId", searchGuid, DataParameterType.UniqueIdentifier)); cmd.Parameters.Add(new DataParameter("CustomerId", CustomerId, DataParameterType.UniqueIdentifier)); cmd.Parameters.Add(new DataParameter("OrderGroupId", OrderGroupId, DataParameterType.Int)); // Might be good idea to signal if there are results at all DataService.Run(cmd); // Load results and return them back MetaStorageCollectionBase <PurchaseOrder> orders = LoadSearchResults(searchGuid); if (orders.Count > 0) { return(orders[0]); } return(null); }
/// <summary> /// Loads cat by name and customer id. /// </summary> /// <param name="CustomerId">The customer id.</param> /// <param name="Name">The name.</param> /// <returns></returns> public static Cart LoadByCustomerAndName(Guid CustomerId, string Name) { Guid searchGuid = Guid.NewGuid(); DataCommand cmd = OrderDataHelper.CreateTranDataCommand(); cmd.CommandText = String.Format("ecf_Search_{0}_CustomerAndName", OrderContext.Current.ShoppingCartMetaClass.Name); cmd.Parameters = new DataParameters(); cmd.Parameters.Add(new DataParameter("ApplicationId", OrderConfiguration.Instance.ApplicationId, DataParameterType.UniqueIdentifier)); cmd.Parameters.Add(new DataParameter("SearchSetId", searchGuid, DataParameterType.UniqueIdentifier)); cmd.Parameters.Add(new DataParameter("CustomerId", CustomerId, DataParameterType.UniqueIdentifier)); cmd.Parameters.Add(new DataParameter("Name", Name, DataParameterType.NVarChar)); cmd.Parameters[2].Size = 64; // Might be good idea to signal if there are results at all DataService.Run(cmd); // Load results and return them back MetaStorageCollectionBase <Cart> carts = LoadSearchResults(searchGuid); if (carts.Count > 0) { return(carts[0]); } return(null); }
/// <summary> /// Finds the carts. /// </summary> /// <param name="parameters">The parameters.</param> /// <param name="options">The options.</param> /// <param name="totalRecords">The total records.</param> /// <returns></returns> public Cart[] FindCarts(OrderSearchParameters parameters, OrderSearchOptions options, out int totalRecords) { OrderSearch search = new OrderSearch(this); search.SearchOptions = options; search.SearchParameters = parameters; MetaStorageCollectionBase <Cart> orders = Cart.Search(search, out totalRecords); return(orders.ToArray()); }
/// <summary> /// Finds the organizations. /// </summary> /// <param name="parameters">The parameters.</param> /// <param name="options">The options.</param> /// <param name="totalRecords">The total records.</param> /// <returns></returns> public Organization[] FindOrganizations(ProfileSearchParameters parameters, ProfileSearchOptions options, out int totalRecords) { ProfileSearch search = new ProfileSearch(this); search.SearchOptions = options; search.SearchParameters = parameters; MetaStorageCollectionBase <Organization> orgs = Organization.Search(search, out totalRecords); return(orgs.ToArray()); }
/// <summary> /// Finds the accounts. /// </summary> /// <param name="parameters">The parameters.</param> /// <param name="options">The options.</param> /// <param name="totalRecords">The total records.</param> /// <returns></returns> public Account[] FindAccounts(ProfileSearchParameters parameters, ProfileSearchOptions options, out int totalRecords) { ProfileSearch search = new ProfileSearch(this); search.SearchOptions = options; search.SearchParameters = parameters; MetaStorageCollectionBase <Account> accounts = Account.Search(search, out totalRecords); return(accounts.ToArray()); }
/// <summary> /// Finds the payment plans. /// </summary> /// <param name="parameters">The parameters.</param> /// <param name="options">The options.</param> /// <param name="totalRecords">The total records.</param> /// <returns></returns> public PaymentPlan[] FindPaymentPlans(OrderSearchParameters parameters, OrderSearchOptions options, out int totalRecords) { OrderSearch search = new OrderSearch(this); search.SearchOptions = options; search.SearchParameters = parameters; MetaStorageCollectionBase <PaymentPlan> orders = PaymentPlan.Search(search, out totalRecords); return(orders.ToArray()); }
/// <summary> /// Loads the search results. /// </summary> /// <param name="SearchGuid">The search GUID.</param> /// <returns></returns> private static MetaStorageCollectionBase <PurchaseOrder> LoadSearchResults(Guid SearchGuid) { DataCommand cmd = OrderDataHelper.CreateTranDataCommand(); cmd.CommandText = String.Format("ecf_Search_{0}", OrderContext.Current.PurchaseOrderMetaClass.Name); cmd.Parameters = new DataParameters(); cmd.Parameters.Add(new DataParameter("SearchSetId", SearchGuid, DataParameterType.UniqueIdentifier)); // Might be good idea to signal if there are results at all DataResult result = DataService.LoadDataSet(cmd); MetaStorageCollectionBase <PurchaseOrder> orders = new MetaStorageCollectionBase <PurchaseOrder>(); PopulateCollection <PurchaseOrder>(OrderContext.Current.PurchaseOrderClassInfo, orders, result.DataSet); return(orders); }
/// <summary> /// Loads the search results. /// </summary> /// <param name="SearchGuid">The search GUID.</param> /// <returns></returns> private static MetaStorageCollectionBase <Account> LoadSearchResults(Guid SearchGuid) { DataCommand cmd = ProfileDataHelper.CreateDataCommand(); cmd.CommandText = String.Format("ecf_Search_{0}", ProfileContext.Current.AccountMetaClass.Name); cmd.Parameters = new DataParameters(); cmd.Parameters.Add(new DataParameter("SearchSetId", SearchGuid, DataParameterType.UniqueIdentifier)); // Might be good idea to signal if there are results at all DataResult result = DataService.LoadDataSet(cmd); MetaStorageCollectionBase <Account> accounts = new MetaStorageCollectionBase <Account>(); PopulateCollection <Account>(ProfileContext.Current.AccountClassInfo, accounts, result.DataSet); return(accounts); }
/// <summary> /// Makes sure that the supplied customer has an active cart. /// </summary> /// <param name="Account"></param> public static void EnsureCustomerCart(Account Account) { Mediachase.Commerce.Orders.Cart activeCart = null; //first, check to see if the "activecart" session key matches up with a real cart, and if it is, we're golden if (Account["ActiveCart"] != null) { activeCart = Mediachase.Commerce.Orders.Cart.LoadByCustomerAndName(Account.PrincipalId, Account["ActiveCart"].ToString()); if (activeCart != null && !NWTD.Orders.Cart.CartCanBeEdited(activeCart)) { activeCart = null; //nope, this cart is not editible, so we need to move along } } //next, we need to see if the customer has any carts at all, create one MetaStorageCollectionBase <Mediachase.Commerce.Orders.Cart> carts = Mediachase.Commerce.Orders.Cart.LoadByCustomer(Account.PrincipalId); //if we still don't have an active cart, we'll loop throught the customer's carts and assign the first valid one we find if (activeCart == null) { foreach (Mediachase.Commerce.Orders.Cart cart in carts) { if (activeCart == null && cart.Status.ToString().Equals(NWTD.Orders.Cart.CART_STATUS.OPEN.ToString())) { activeCart = cart; } } } //finally, if there is still no active cart, create the damn thing if (activeCart == null) { //first, we have to make sure we come up with a unique name. string baseName = Mediachase.Commerce.Orders.Cart.DefaultName; string cartName = baseName; int iterations = 1; while (Mediachase.Commerce.Orders.Cart.LoadByCustomerAndName(Account.PrincipalId, cartName) != null) { cartName = string.Format("{0}-{1}", baseName, iterations.ToString()); iterations++; } activeCart = NWTD.Orders.Cart.CreateCart(Account, cartName); } AssignActiveCart(Account, activeCart); }
/// <summary> /// Loads the by provider key. /// </summary> /// <param name="ProviderKey">The provider key.</param> /// <returns></returns> internal static Account LoadByProviderKey(string ProviderKey) { Guid searchGuid = Guid.NewGuid(); DataCommand cmd = ProfileDataHelper.CreateDataCommand(); cmd.CommandText = String.Format("ecf_Search_{0}_ProviderKey", ProfileContext.Current.AccountMetaClass.Name); cmd.Parameters = new DataParameters(); cmd.Parameters.Add(new DataParameter("ApplicationId", ProfileConfiguration.Instance.ApplicationId, DataParameterType.UniqueIdentifier)); cmd.Parameters.Add(new DataParameter("SearchSetId", searchGuid, DataParameterType.UniqueIdentifier)); cmd.Parameters.Add(new DataParameter("ProviderKey", ProviderKey, DataParameterType.NVarChar)); // Might be good idea to signal if there are results at all DataService.Run(cmd); // Load results and return them back MetaStorageCollectionBase <Account> accounts = LoadSearchResults(searchGuid); if (accounts.Count > 0) { return(accounts[0]); } return(null); }
/// <summary> /// Loads the by id. /// </summary> /// <param name="organizationId">The organization id.</param> /// <returns></returns> public static Organization LoadById(int organizationId) { Guid searchGuid = Guid.NewGuid(); DataCommand cmd = ProfileDataHelper.CreateDataCommand(); cmd.CommandText = String.Format("ecf_Search_{0}_OrganizationId", ProfileContext.Current.OrganizationMetaClass.Name); cmd.Parameters = new DataParameters(); cmd.Parameters.Add(new DataParameter("ApplicationId", ProfileConfiguration.Instance.ApplicationId, DataParameterType.UniqueIdentifier)); cmd.Parameters.Add(new DataParameter("SearchSetId", searchGuid, DataParameterType.UniqueIdentifier)); cmd.Parameters.Add(new DataParameter("OrganizationId", organizationId, DataParameterType.Int)); // Might be good idea to signal if there are results at all DataService.Run(cmd); MetaStorageCollectionBase <Organization> orgs = LoadSearchResults(searchGuid); if (orgs.Count > 0) { return(orgs[0]); } // Load results and return them back return(null); }
public void OrderSystem_GetCartsForACustomer() { Cart firstCart = null; Cart secondCart = null; MetaStorageCollectionBase <Cart> carts = null; Guid customerId; //first add fictitious carts into the db customerId = Guid.NewGuid(); //Create cart 1. This cart is just used to get the lineitem meta class information try { firstCart = OrderHelper.CreateCart(customerId, "FirstTestCart"); firstCart.AcceptChanges(); } catch (Exception exc) { if (exc.Message == "'maxValue' must be greater than zero.\r\nParameter name: maxValue") { Assert.Fail("Check your ApplicationId"); } else { throw exc; } } //Create cart 1. This cart is just used to get the lineitem meta class information try { secondCart = OrderHelper.CreateCart(customerId, "SecondTestCart"); secondCart.AcceptChanges(); } catch (Exception exc) { if (exc.Message == "'maxValue' must be greater than zero.\r\nParameter name: maxValue") { Assert.Fail("Check your ApplicationId"); } else { throw exc; } } try { carts = Cart.LoadByCustomer(customerId); } catch (Exception exc) { Assert.Fail("Error calling Cart.LoadByCustomer method : " + exc.Message); } if (carts.Count != 2) { Assert.Fail("Incorrect number of carts found by Cart.LoadByCustomer(). Found: " + carts.Count); } //cleanup firstCart.Delete(); firstCart.AcceptChanges(); secondCart.Delete(); secondCart.AcceptChanges(); }
/// <summary> /// Populates the collection. /// </summary> /// <typeparam name="T"></typeparam> /// <param name="classInfo">The class info.</param> /// <param name="collection">The collection.</param> /// <param name="dataSet">The data set.</param> protected static void PopulateCollection <T>(ClassInfo classInfo, MetaStorageCollectionBase <T> collection, DataSet dataSet) where T : OrderGroup { #region ArgumentNullExceptions if (dataSet == null) { throw new ArgumentNullException("dataSet"); } #endregion DataTableCollection tables = dataSet.Tables; if (tables == null || tables.Count == 0) { return; } // Get the collection that contains ids of all items returned DataRowCollection dataRowCol = tables[0].Rows; // No ids returned if (dataRowCol == null || dataRowCol.Count == 0) { return; } int numberOfRecords = dataRowCol.Count; int[] idArray = new int[numberOfRecords]; // Populate array for (int index = 0; index < numberOfRecords; index++) { idArray[index] = (int)dataRowCol[index]["OrderGroupId"]; } // Remove id collection tables.RemoveAt(0); // Map table names foreach (DataTable table in dataSet.Tables) { if (table.Rows.Count > 0) { table.TableName = table.Rows[0]["TableName"].ToString(); } } // Cycle through id Collection foreach (int id in idArray) { string filter = String.Format("OrderGroupId = '{0}'", id.ToString()); // Populate the meta object data first // Meta data will be always in the second table returned DataView view = DataHelper.CreateDataView(dataSet.Tables["OrderGroup"], filter); // Only read one record, since we are populating only one object // reader.Read(); // Create instance of the object specified and populate it T obj = (T)classInfo.CreateInstance(); obj.Load(view[0]); collection.Add(obj); // Populate collections within object obj.PopulateCollections(dataSet.Tables, filter); /* * if (dataSet.Tables.Count != 0) * { * throw new ArgumentOutOfRangeException("Tables", "Stored Procedure returned too many tables"); * } * */ } }
/// <summary> /// Gets the payment plans. /// </summary> /// <param name="customerId">The customer id.</param> /// <returns></returns> public PaymentPlan[] GetPaymentPlans(Guid customerId) { MetaStorageCollectionBase <PaymentPlan> orders = PaymentPlan.LoadByCustomer(customerId); return(orders.ToArray()); }
/// <summary> /// Gets the purchase orders. /// </summary> /// <param name="customerId">The customer id.</param> /// <returns></returns> public PurchaseOrder[] GetPurchaseOrders(Guid customerId) { MetaStorageCollectionBase <PurchaseOrder> orders = PurchaseOrder.LoadByCustomer(customerId); return(orders.ToArray()); }