public List <Customer> GetCustomersForParentAccountOrganization(string accountId) { var customerFromCache = _customerCacheRepository.GetItem <List <Customer> >(CACHE_GROUPNAME, CACHE_PREFIX, CACHE_NAME, GetCacheKey(string.Format("acct-{0}", accountId))); if (customerFromCache == null) { } else { return(customerFromCache); } var queryOrg = new CommerceServer.Foundation.CommerceQuery <KeithLink.Svc.Core.Models.Generated.Organization>("Organization"); queryOrg.SearchCriteria.WhereClause = "u_parent_organization = '" + accountId + "'"; // org type of customer CommerceQueryOperationResponse res = (Svc.Impl.Helpers.FoundationService.ExecuteRequest(queryOrg.ToRequest())).OperationResponses[0] as CommerceQueryOperationResponse; List <Customer> results = BuildCustomerList(res.CommerceEntities); if (results.Count > 0) { _customerCacheRepository.AddItem <List <Customer> >(CACHE_GROUPNAME, CACHE_PREFIX, CACHE_NAME, GetCacheKey(string.Format("acct-{0}", accountId)), TimeSpan.FromHours(4), results); } return(results); }
public Customer GetCustomerByCustomerNumber(string customerNumber, string branchId) { var customerFromCache = _customerCacheRepository.GetItem <Customer>(CACHE_GROUPNAME, CACHE_PREFIX, CACHE_NAME, GetCacheKey(string.Format("{0}-{1}", customerNumber, branchId))); if (customerFromCache == null) { var queryOrg = new CommerceServer.Foundation.CommerceQuery <KeithLink.Svc.Core.Models.Generated.Organization>("Organization"); queryOrg.SearchCriteria.WhereClause = "u_organization_type = '0' AND u_customer_number = '" + customerNumber + "' AND u_branch_number = '" + branchId + "'"; // org type of customer CommerceQueryOperationResponse res = (Svc.Impl.Helpers.FoundationService.ExecuteRequest(queryOrg.ToRequest())).OperationResponses[0] as CommerceQueryOperationResponse; if (res.CommerceEntities.Count > 0) { List <Customer> results = BuildCustomerList(res.CommerceEntities); _customerCacheRepository.AddItem <Customer>(CACHE_GROUPNAME, CACHE_PREFIX, CACHE_NAME, GetCacheKey(string.Format("{0}-{1}", customerNumber, branchId)), TimeSpan.FromHours(4), results[0]); return(results[0]); } else { return(null); } } else { return(customerFromCache); } }
public List <Core.Models.Profile.Account> GetAccountsForUser(Guid userId) { // get user organization info var profileQuery = new CommerceServer.Foundation.CommerceQuery <CommerceServer.Foundation.CommerceEntity>("UserOrganizations"); profileQuery.SearchCriteria.Model.Properties["UserId"] = userId.ToCommerceServerFormat(); CommerceServer.Foundation.CommerceResponse res = Svc.Impl.Helpers.FoundationService.ExecuteRequest(profileQuery.ToRequest()); List <Account> userAccounts = new List <Account>(); foreach (CommerceEntity ent in (res.OperationResponses[0] as CommerceQueryOperationResponse).CommerceEntities) { Organization org = new Organization(ent); if (org.OrganizationType == "1") { userAccounts.Add(new Account() { Id = Guid.Parse(org.Id), Name = org.Name, }); } } return(userAccounts); }
public List <Customer> GetCustomersByNameOrNumber(string search) { var queryOrg = new CommerceServer.Foundation.CommerceQuery <KeithLink.Svc.Core.Models.Generated.Organization>("Organization"); queryOrg.SearchCriteria.WhereClause = "u_name LIKE '%" + search + "%' OR u_customer_number LIKE '%" + search + "%'"; CommerceQueryOperationResponse res = (Svc.Impl.Helpers.FoundationService.ExecuteRequest(queryOrg.ToRequest())).OperationResponses[0] as CommerceQueryOperationResponse; List <Customer> results = BuildCustomerList(res.CommerceEntities); return(results); }
protected KeithLink.Svc.Core.Models.Generated.SiteTerm GetOrganizationTypes() { var siteTermQuery = new CommerceServer.Foundation.CommerceQuery <KeithLink.Svc.Core.Models.Generated.SiteTerm>("SiteTerm"); siteTermQuery.SearchCriteria.Model.Properties["Id"] = "OrganizationType"; siteTermQuery.RelatedOperations.Add( new CommerceQueryRelatedItem <KeithLink.Svc.Core.Models.Generated.SiteTermElement> (KeithLink.Svc.Core.Models.Generated.SiteTerm.RelationshipName.Elements)); CommerceQueryOperationResponse res = (Svc.Impl.Helpers.FoundationService.ExecuteRequest(siteTermQuery.ToRequest())).OperationResponses[0] as CommerceQueryOperationResponse; return(new KeithLink.Svc.Core.Models.Generated.SiteTerm(res.CommerceEntities[0])); }
/// <summary> /// perform the seach for all of the paged customer methods /// </summary> /// <param name="paging">paging model</param> /// <param name="searchTerm">the terms to use during the search</param> /// <param name="whereClause">the where clause that was built in each of the GetPageCustomer methods</param> /// <param name="searchType">search on customer name/number, NA, or RA info</param> /// <returns>paged list of customers</returns> private PagedResults <Customer> RetrievePagedResults(PagingModel paging, string searchTerm, string whereClause, CustomerSearchType searchType) { var queryOrg = new CommerceServer.Foundation.CommerceQuery <KeithLink.Svc.Core.Models.Generated.Organization>("Organization"); queryOrg.SearchCriteria.WhereClause = BuildWhereClauseForCustomerSearch(whereClause, searchTerm, searchType); queryOrg.SearchCriteria.FirstItemIndex = paging.From.HasValue ? paging.From.Value : 0; queryOrg.SearchCriteria.NumberOfItemsToReturn = paging.Size.HasValue ? paging.Size.Value : int.MaxValue; queryOrg.SearchCriteria.ReturnTotalItemCount = true; if (paging.Sort != null && paging.Sort.Count > 0) { queryOrg.SearchCriteria.SortProperties = new List <CommerceSortProperty>(); foreach (var sortOption in paging.Sort) { switch (sortOption.Field.ToLower()) { case "customername": CommerceSortProperty sortName = new CommerceSortProperty() { CommerceEntityModelName = "u_name", SortDirection = sortOption.SortOrder == SortOrder.Ascending ? SortDirection.Ascending : SortDirection.Descending }; queryOrg.SearchCriteria.SortProperties.Add(sortName); break; case "customernumber": CommerceSortProperty sortNumber = new CommerceSortProperty() { CommerceEntityModelName = "u_customer_number", SortDirection = sortOption.SortOrder == SortOrder.Ascending ? SortDirection.Ascending : SortDirection.Descending }; queryOrg.SearchCriteria.SortProperties.Add(sortNumber); break; } } } CommerceQueryOperationResponse res = (Svc.Impl.Helpers.FoundationService.ExecuteRequest(queryOrg.ToRequest())).OperationResponses[0] as CommerceQueryOperationResponse; List <Customer> results = BuildCustomerList(res.CommerceEntities); return(new PagedResults <Customer>() { Results = results.ToList(), TotalResults = res.TotalItemCount ?? 0 }); }
public List <Customer> GetCustomersForDSR(List <Dsr> dsrList) { var queryOrg = new CommerceServer.Foundation.CommerceQuery <KeithLink.Svc.Core.Models.Generated.Organization>("Organization"); System.Text.StringBuilder whereText = new System.Text.StringBuilder(); for (int i = 0; i < dsrList.Count; i++) { if (i > 0) { whereText.Append(" OR "); } whereText.AppendFormat("(u_branch_number = '{0}' AND u_dsr_number = '{1}')", dsrList[i].Branch, dsrList[i].DsrNumber); } queryOrg.SearchCriteria.WhereClause = whereText.ToString(); CommerceQueryOperationResponse res = (Svc.Impl.Helpers.FoundationService.ExecuteRequest(queryOrg.ToRequest())).OperationResponses[0] as CommerceQueryOperationResponse; List <Customer> results = BuildCustomerList(res.CommerceEntities); return(results); }
public Customer GetCustomerForUser(string customerNumber, string branchId, Guid userId) { var queryOrg = new CommerceServer.Foundation.CommerceQuery <KeithLink.Svc.Core.Models.Generated.Organization>("Organization"); queryOrg.SearchCriteria.WhereClause = string.Format("inner join [BEK_Commerce_profiles].[dbo].[UserOrganizationObject] uoo on oo.u_org_id = uoo.u_org_id WHERE uoo.u_user_id = '{0}' AND u_customer_number = '{1}' AND u_branch_number = '{2}'", userId.ToCommerceServerFormat(), customerNumber, branchId); CommerceQueryOperationResponse res = (Svc.Impl.Helpers.FoundationService.ExecuteRequest(queryOrg.ToRequest())).OperationResponses[0] as CommerceQueryOperationResponse; if (res.CommerceEntities.Count > 0) { List <Customer> results = BuildCustomerList(res.CommerceEntities); return(results[0]); } else { return(null); } }
public List <Customer> GetCustomersByNameSearch(string searchText) { var customerFromCache = _customerCacheRepository.GetItem <List <Customer> >(CACHE_GROUPNAME, CACHE_PREFIX, CACHE_NAME, GetCacheKey(searchText)); if (customerFromCache == null) { var queryOrg = new CommerceServer.Foundation.CommerceQuery <KeithLink.Svc.Core.Models.Generated.Organization>("Organization"); queryOrg.SearchCriteria.WhereClause = "u_name LIKE '%" + searchText.Replace("'", "''") + "%'"; // org type of customer CommerceQueryOperationResponse res = (Svc.Impl.Helpers.FoundationService.ExecuteRequest(queryOrg.ToRequest())).OperationResponses[0] as CommerceQueryOperationResponse; List <Customer> results = BuildCustomerList(res.CommerceEntities); _customerCacheRepository.AddItem <List <Customer> >(CACHE_GROUPNAME, CACHE_PREFIX, CACHE_NAME, GetCacheKey(searchText), TimeSpan.FromMinutes(2), results); return(results); } else { return(customerFromCache); } }
/// <summary> /// create a profile for the user in commerce server /// </summary> /// <param name="emailAddress">the user's email address</param> /// <param name="firstName">user's given name</param> /// <param name="lastName">user's surname</param> /// <param name="phoneNumber">user's telephone number</param> /// <remarks> /// jwames - 10/3/2014 - documented /// </remarks> public List <Customer> GetCustomers() { var allCustomersFromCache = _customerCacheRepository.GetItem <List <Customer> >(CACHE_GROUPNAME, CACHE_PREFIX, CACHE_NAME, GetCacheKey("allCustomers")); if (allCustomersFromCache == null) { var queryOrg = new CommerceServer.Foundation.CommerceQuery <KeithLink.Svc.Core.Models.Generated.Organization>("Organization"); queryOrg.SearchCriteria.WhereClause = "u_organization_type = '0'"; // org type of customer CommerceQueryOperationResponse res = (Svc.Impl.Helpers.FoundationService.ExecuteRequest(queryOrg.ToRequest())).OperationResponses[0] as CommerceQueryOperationResponse; List <Customer> results = BuildCustomerList(res.CommerceEntities); _customerCacheRepository.AddItem <List <Customer> >(CACHE_GROUPNAME, CACHE_PREFIX, CACHE_NAME, GetCacheKey("allCustomers"), TimeSpan.FromHours(4), results); return(results); } else { return(allCustomersFromCache); } }
public List <Customer> GetCustomersForUser(Guid userId) { var customerFromCache = _customerCacheRepository.GetItem <List <Customer> >(CACHE_GROUPNAME, CACHE_PREFIX, CACHE_NAME, GetCacheKey(string.Format("user_{0}", userId.ToString()))); if (customerFromCache != null && customerFromCache.Count > 0) { //} else { return(customerFromCache); } // get user organization info var profileQuery = new CommerceServer.Foundation.CommerceQuery <CommerceServer.Foundation.CommerceEntity>("UserOrganizations"); profileQuery.SearchCriteria.Model.Properties["UserId"] = userId.ToCommerceServerFormat(); CommerceQueryOperationResponse res = (FoundationService.ExecuteRequest(profileQuery.ToRequest())).OperationResponses[0] as CommerceQueryOperationResponse; List <Customer> results = BuildCustomerList(res.CommerceEntities); _customerCacheRepository.AddItem <List <Customer> >(CACHE_GROUPNAME, CACHE_PREFIX, CACHE_NAME, GetCacheKey(string.Format("user_{0}", userId.ToString())), TimeSpan.FromHours(4), results); return(results); }
public List <Account> GetAccounts() { var queryOrg = new CommerceServer.Foundation.CommerceQuery <KeithLink.Svc.Core.Models.Generated.Organization>("Organization"); queryOrg.SearchCriteria.WhereClause = "u_organization_type = '1'"; // org type of account CommerceQueryOperationResponse res = (Svc.Impl.Helpers.FoundationService.ExecuteRequest(queryOrg.ToRequest())).OperationResponses[0] as CommerceQueryOperationResponse; var accounts = new System.Collections.Concurrent.BlockingCollection <Account>(); System.Threading.Tasks.Parallel.ForEach(res.CommerceEntities, e => { KeithLink.Svc.Core.Models.Generated.Organization org = new KeithLink.Svc.Core.Models.Generated.Organization(e); accounts.Add(new Account() { Id = Guid.Parse(org.Id), Name = org.Name, }); }); return(accounts.ToList()); }