Ejemplo n.º 1
0
        public static Customer ToCustomer(this CS.Organization org)
        {
            Customer customer = new Customer()
            {
                CustomerId     = Guid.Parse(org.Id),
                AccountId      = String.IsNullOrEmpty(org.ParentOrganizationId) ? new Nullable <Guid>() : Guid.Parse(org.ParentOrganizationId),
                ContractId     = org.ContractNumber,
                DisplayName    = string.Format("{0} - {1}", org.CustomerNumber, org.Name),
                CustomerBranch = org.BranchNumber,
                CustomerName   = org.Name,
                CustomerNumber = org.CustomerNumber,
                DsrNumber      = org.DsrNumber,
                IsPoRequired   = org.IsPoRequired.HasValue ? org.IsPoRequired.Value : false,
                IsPowerMenu    = org.IsPowerMenu.HasValue ? org.IsPowerMenu.Value : false,
                // TODO - fill this in from real data source
                Phone = org.PreferredAddress != null &&
                        !String.IsNullOrEmpty(org.PreferredAddress.Telephone) &&
                        !org.PreferredAddress.Telephone.Equals("0000000000") ? org.PreferredAddress.Telephone : string.Empty, // get from address profile
                Email                 = string.Empty,
                PointOfContact        = string.Empty,
                TermCode              = org.TermCode,
                KPayCustomer          = org.AchType == "2" || org.AchType == "3",
                DsmNumber             = org.DsmNumber,
                NationalId            = org.NationalId,
                NationalNumber        = org.NationalNumber,
                NationalSubNumber     = org.NationalSubNumber,
                RegionalId            = org.RegionalId,
                RegionalNumber        = org.RegionalNumber,
                IsKeithNetCustomer    = org.IsKeithnetCustomer != null && org.IsKeithnetCustomer.ToLower() == "y" ? true : false,
                NationalIdDesc        = !String.IsNullOrEmpty(org.NationalIdDesc) ? org.NationalIdDesc.Trim() : String.Empty,
                NationalNumberSubDesc = !String.IsNullOrEmpty(org.NationalNumberSubDesc) ? org.NationalNumberSubDesc.Trim() : String.Empty,
                RegionalIdDesc        = !String.IsNullOrEmpty(org.RegionalIdDesc) ? org.RegionalIdDesc.Trim() : String.Empty,
                RegionalNumberDesc    = !String.IsNullOrEmpty(org.RegionalNumberDesc) ? org.RegionalNumberDesc.Trim() : String.Empty,
                CanViewPricing        = org.CanViewPricing ?? true
            };

            // fill in the address
            customer.Address = org.PreferredAddress != null ? new Address()
            {
                StreetAddress =
                    !String.IsNullOrEmpty(org.PreferredAddress.Line1) && !String.IsNullOrEmpty(org.PreferredAddress.Line2)
                    ? org.PreferredAddress.Line1 + System.Environment.NewLine + org.PreferredAddress.Line2
                    : !String.IsNullOrEmpty(org.PreferredAddress.Line1) ? org.PreferredAddress.Line1 : string.Empty,
                City       = !String.IsNullOrEmpty(org.PreferredAddress.City) ? org.PreferredAddress.City : string.Empty,
                RegionCode = !String.IsNullOrEmpty(org.PreferredAddress.StateProvinceCode) ? org.PreferredAddress.StateProvinceCode : string.Empty,
                PostalCode = !String.IsNullOrEmpty(org.PreferredAddress.ZipPostalCode) ? org.PreferredAddress.ZipPostalCode : string.Empty
            }
                    : new Address()
            {
                StreetAddress = string.Empty, City = string.Empty, RegionCode = string.Empty, PostalCode = string.Empty
            };

            return(customer);
        }
Ejemplo n.º 2
0
        private List <Customer> BuildCustomerList(List <CommerceEntity> organizations)
        {
            var customers = new System.Collections.Concurrent.BlockingCollection <Customer>();
            Dictionary <string, Dsr>    dsrDict  = RetrieveDsrDictionary();
            Dictionary <string, string> termDict = RetrieveTermsCodeDict();

            System.Threading.Tasks.Parallel.ForEach(organizations, e => {
                Organization org = new KeithLink.Svc.Core.Models.Generated.Organization(e);

                if (org.OrganizationType == ORGANIZATION_TYPE_CUSTOMER)
                {
                    Customer myCustomer = org.ToCustomer();

                    string termKey = GetTermKey(org.BranchNumber, org.TermCode);

                    if (termDict.ContainsKey(termKey))
                    {
                        myCustomer.TermDescription = termDict[termKey];
                    }

                    string dsrKey = GetDsrKey(myCustomer.CustomerBranch, myCustomer.DsrNumber);
                    Dsr myDsr     = null;

                    if (dsrDict.ContainsKey(dsrKey))
                    {
                        myDsr = dsrDict[dsrKey];
                    }
                    else
                    {
                        dsrKey = GetDsrKey(myCustomer.CustomerBranch, DEFAULT_DSR_NUMBER);
                        if (dsrDict.ContainsKey(dsrKey))
                        {
                            myDsr = dsrDict[dsrKey];
                        }
                    }

                    myCustomer.Dsr = myDsr;

                    customers.Add(myCustomer);
                }
            });

            return(customers.ToList());
        }
Ejemplo n.º 3
0
        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());
        }